From fe96ea49effc11de21f6d3efde2097f14ac43fff Mon Sep 17 00:00:00 2001 From: eric-j-ason <75301977+eric-j-ason@users.noreply.github.com> Date: Wed, 8 Nov 2023 20:19:06 +0100 Subject: [PATCH] Add test for ucode (#881) --- lexers/testdata/ucode.actual | 61 +++++ lexers/testdata/ucode.expected | 424 +++++++++++++++++++++++++++++++++ 2 files changed, 485 insertions(+) create mode 100644 lexers/testdata/ucode.actual create mode 100644 lexers/testdata/ucode.expected diff --git a/lexers/testdata/ucode.actual b/lexers/testdata/ucode.actual new file mode 100644 index 000000000..04ed416a7 --- /dev/null +++ b/lexers/testdata/ucode.actual @@ -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; diff --git a/lexers/testdata/ucode.expected b/lexers/testdata/ucode.expected new file mode 100644 index 000000000..1ddcc088d --- /dev/null +++ b/lexers/testdata/ucode.expected @@ -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"} +]