1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-03-17 20:58:08 +02:00

Add test for ucode (#881)

This commit is contained in:
eric-j-ason 2023-11-08 20:19:06 +01:00 committed by GitHub
parent 8f938d02c5
commit fe96ea49ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 485 additions and 0 deletions

61
lexers/testdata/ucode.actual vendored Normal file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env ucode
import { open } from "fs";
import * as o from "fs";
// This is a comment on a line of its own.
function abcd(x, ...values) {
print(...values, "\n");
return null;
}
let x_5 = 5; // This is a comment on a line of code.
let id = x => x;
let empty = () => 0;
let add = (a, b) => a + b;
if (true) {
abcd(0);
} else if (false) {
abcd("a");
} else {
abcd([0, 1, 2]);
}
for (let i in [0, 1, 2]) {
}
for (let i = 0; i < 10; i++) {
}
let count = 5;
while (count--) {
continue;
}
switch (x) {
case 6:
x = 8.8;
break;
default:
x = -9.7e2;
}
try {
die("");
} catch {
}
match("foobarbaz", /b.(.)/)
let obj = {a: abcd, b: -1, c: (x) => 2*x, d: [], e: {}, f: function(n) {return this;}};
delete obj.a;
let a = Infinity;
let b = NaN;
let c = "abc";
let d = 'abc';
let e = `aaa ${id(5)} bbb \u2600`;
export id;

424
lexers/testdata/ucode.expected vendored Normal file
View File

@ -0,0 +1,424 @@
[
{"type":"CommentHashbang","value":"#!/usr/bin/env ucode\n"},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"import"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"open"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"from"},
{"type":"Text","value":" "},
{"type":"LiteralStringDouble","value":"\"fs\""},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"import"},
{"type":"Text","value":" "},
{"type":"Operator","value":"*"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"as"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"o"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"from"},
{"type":"Text","value":" "},
{"type":"LiteralStringDouble","value":"\"fs\""},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"// This is a comment on a line of its own.\n"},
{"type":"KeywordDeclaration","value":"function"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"abcd"},
{"type":"Punctuation","value":"("},
{"type":"NameOther","value":"x"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"..."},
{"type":"NameOther","value":"values"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n\t"},
{"type":"NameOther","value":"print"},
{"type":"Punctuation","value":"(..."},
{"type":"NameOther","value":"values"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"LiteralStringDouble","value":"\"\\n\""},
{"type":"Punctuation","value":");"},
{"type":"Text","value":"\n\t"},
{"type":"Keyword","value":"return"},
{"type":"Text","value":" "},
{"type":"KeywordConstant","value":"null"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"KeywordDeclaration","value":"let"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"x_5"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"5"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":" "},
{"type":"CommentSingle","value":"// This is a comment on a line of code.\n"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"let"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"id"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"NameOther","value":"x"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"=\u003e"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"x"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"let"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"empty"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"()"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"=\u003e"},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"0"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"let"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"add"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"("},
{"type":"NameOther","value":"a"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"NameOther","value":"b"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"=\u003e"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"a"},
{"type":"Text","value":" "},
{"type":"Operator","value":"+"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"b"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"if"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"("},
{"type":"KeywordConstant","value":"true"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n\t"},
{"type":"NameOther","value":"abcd"},
{"type":"Punctuation","value":"("},
{"type":"LiteralNumberInteger","value":"0"},
{"type":"Punctuation","value":");"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"else"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"if"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"("},
{"type":"KeywordConstant","value":"false"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n\t"},
{"type":"NameOther","value":"abcd"},
{"type":"Punctuation","value":"("},
{"type":"LiteralStringDouble","value":"\"a\""},
{"type":"Punctuation","value":");"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"else"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n\t"},
{"type":"NameOther","value":"abcd"},
{"type":"Punctuation","value":"(["},
{"type":"LiteralNumberInteger","value":"0"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"1"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"2"},
{"type":"Punctuation","value":"]);"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"for"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"("},
{"type":"KeywordDeclaration","value":"let"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"i"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"in"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"["},
{"type":"LiteralNumberInteger","value":"0"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"1"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"2"},
{"type":"Punctuation","value":"])"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"for"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"("},
{"type":"KeywordDeclaration","value":"let"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"i"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"0"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"i"},
{"type":"Text","value":" "},
{"type":"Operator","value":"\u003c"},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"10"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"i"},
{"type":"Operator","value":"++"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"KeywordDeclaration","value":"let"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"count"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"5"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"while"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"("},
{"type":"NameOther","value":"count"},
{"type":"Operator","value":"--"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n\t"},
{"type":"Keyword","value":"continue"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"switch"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"("},
{"type":"NameOther","value":"x"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"case"},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"6"},
{"type":"Operator","value":":"},
{"type":"Text","value":"\n\t"},
{"type":"NameOther","value":"x"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"8.8"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n\t"},
{"type":"Keyword","value":"break"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"default"},
{"type":"Operator","value":":"},
{"type":"Text","value":"\n\t"},
{"type":"NameOther","value":"x"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Operator","value":"-"},
{"type":"LiteralNumberFloat","value":"9.7"},
{"type":"NameOther","value":"e2"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"try"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n\t"},
{"type":"NameOther","value":"die"},
{"type":"Punctuation","value":"("},
{"type":"LiteralStringDouble","value":"\"\""},
{"type":"Punctuation","value":");"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"catch"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"NameOther","value":"match"},
{"type":"Punctuation","value":"("},
{"type":"LiteralStringDouble","value":"\"foobarbaz\""},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"LiteralStringRegex","value":"/b.(.)/"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n\n"},
{"type":"KeywordDeclaration","value":"let"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"obj"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"NameOther","value":"a"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"abcd"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"NameOther","value":"b"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"Operator","value":"-"},
{"type":"LiteralNumberInteger","value":"1"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"NameOther","value":"c"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"("},
{"type":"NameOther","value":"x"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"=\u003e"},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"2"},
{"type":"Operator","value":"*"},
{"type":"NameOther","value":"x"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"NameOther","value":"d"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"[],"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"e"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{},"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"f"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"KeywordDeclaration","value":"function"},
{"type":"Punctuation","value":"("},
{"type":"NameOther","value":"n"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Keyword","value":"return"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"this"},
{"type":"Punctuation","value":";}};"},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"delete"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"obj"},
{"type":"Punctuation","value":"."},
{"type":"NameOther","value":"a"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n\n"},
{"type":"KeywordDeclaration","value":"let"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"a"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"KeywordConstant","value":"Infinity"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"let"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"b"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"KeywordConstant","value":"NaN"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"let"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"c"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralStringDouble","value":"\"abc\""},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"let"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"d"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralStringSingle","value":"'abc'"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"let"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"e"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralStringBacktick","value":"`aaa "},
{"type":"LiteralStringInterpol","value":"${"},
{"type":"NameOther","value":"id"},
{"type":"Punctuation","value":"("},
{"type":"LiteralNumberInteger","value":"5"},
{"type":"Punctuation","value":")"},
{"type":"LiteralStringInterpol","value":"}"},
{"type":"LiteralStringBacktick","value":" bbb \\u2600`"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"export"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"id"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"}
]