diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index d6bf8415d..06da24d0c 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -31,7 +31,15 @@ jobs: with: cmd: ci # will run `yarn run ci` command + - name: Run SonarCloud scan + if: matrix.os == 'ubuntu-latest' && matrix.node-version == '14.x' + uses: sonarsource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.ACCESS_PAT }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + - name: Upload vsix artifact + if: matrix.os == 'ubuntu-latest' && matrix.node-version == '14.x' && github.event_name == 'push' uses: actions/upload-artifact@v3 with: name: vscode-extension-file diff --git a/.gitignore b/.gitignore index b6e9f31f5..0c48cd778 100644 --- a/.gitignore +++ b/.gitignore @@ -43,7 +43,7 @@ bower_components build/Release # Dependency directories -node_modules/ +node_modules jspm_packages/ # TypeScript v1 declaration files @@ -97,3 +97,7 @@ test-packages/test-utils/.model-cache # MacOS cache .DS_Store + +# Test reports +junit-report.xml +test-report.xml diff --git a/.vscode/launch.json b/.vscode/launch.json index 66e635666..68a82ca17 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -44,35 +44,135 @@ { "type": "node", "request": "launch", - "name": "context: run current file", - "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", - "args": ["${fileBasenameNoExtension}"], + "name": "Context: Run Current Jest File", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": [ + "${fileBasenameNoExtension}", + "--coverage=false", + "--config", + "jest.config.js" + ], "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest/bin/jest" + }, "cwd": "${workspaceFolder}/packages/context" }, { "type": "node", "request": "launch", - "name": "fe: run current file", - "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", - "args": ["${fileBasenameNoExtension}"], + "name": "Language Server: Run Current Jest File", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": [ + "${fileBasenameNoExtension}", + "--coverage=false", + "--config", + "jest.config.js" + ], "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "disableOptimisticBPs": true, - "cwd": "${workspaceFolder}/packages/fe" + "windows": { + "program": "${workspaceFolder}/node_modules/jest/bin/jest" + }, + "cwd": "${workspaceFolder}/packages/language-server" + }, + { + "type": "node", + "request": "launch", + "name": "Extension: Run Current Jest File", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": [ + "${fileBasenameNoExtension}", + "--coverage=false", + "--config", + "jest.config.js" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest/bin/jest" + }, + "cwd": "${workspaceFolder}/packages/vscode-ui5-language-assistant" }, { "type": "node", "request": "launch", - "name": "semantic-model: run current file", - "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", - "args": ["${fileBasenameNoExtension}"], + "name": "XML validation: Run Current Jest File", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": [ + "${fileBasenameNoExtension}", + "--coverage=false", + "--config", + "jest.config.js" + ], "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest/bin/jest" + }, + "cwd": "${workspaceFolder}/packages/xml-views-validation" + }, + { + "type": "node", + "request": "launch", + "name": "Logic Utils: Run Current Jest File", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": [ + "${fileBasenameNoExtension}", + "--coverage=false", + "--config", + "jest.config.js" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest/bin/jest" + }, + "cwd": "${workspaceFolder}/packages/logic-utils" + }, + { + "type": "node", + "request": "launch", + "name": "Semantic Model: Run Current Jest File", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": [ + "${fileBasenameNoExtension}", + "--coverage=false", + "--config", + "jest.config.js" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest/bin/jest" + }, "cwd": "${workspaceFolder}/packages/semantic-model" + }, + { + "type": "node", + "request": "launch", + "name": "Annotations Module (FE): Run Current Jest File", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": [ + "${fileBasenameNoExtension}", + "--coverage=false", + "--config", + "jest.config.js" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest/bin/jest" + }, + "cwd": "${workspaceFolder}/packages/fe" } ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 26de15565..4be0cfec3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,3 @@ { - "files.watcherExclude": { - "**/node_modules/*/**": false, - "**/node_modules/[!@]*/**/*": true - } + "files.watcherExclude": {} } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6aeab05de..d9178a170 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -57,15 +57,13 @@ use the top level scripts to avoid forgetting to (re-)compile a sub-package's de ### Testing -[Mocha][mocha] is used for unit-testing and [Istanbul/Nyc][istanbul] for coverage reports. -Jest was avoided due to increased total tests execution time due to running the tests in multiple processes, -as the Parser initialization (which happens once per process) can take 10-20ms. +[Jest][jest] is used for unit-testing and coverage reports and [Istanbul/Nyc][istanbul] is used to collect integrated coverage report. -[mocha]: https://mochajs.org/ +[jest]: https://jestjs.io/ [istanbul]: https://istanbul.js.org/ - To run the tests run `yarn test` in either the top level package or a specific subpackage. -- To run the tests with a coverage report run `yarn coverage:run` in either the top level package or a specific subpackage. +- To run the tests with a coverage report run `yarn coverage` in either the top level package or a specific subpackage. #### Debugging @@ -75,7 +73,7 @@ Open the `package.json` file of the package and debug the `test` script. It will **In VS Code:** -To debug tests in VS Code, in the root [`launch.json`](./.vscode/launch.json) file, add a `Node.js: Mocha Tests` configuration by using code assist. +To debug tests in VS Code, in the root [`launch.json`](./.vscode/launch.json) file, add a `Node.js: Jest Tests` configuration by using code assist. Change the following in the added configuration: - Change `tdd` to `bdd` under the `args` property @@ -88,8 +86,8 @@ The result should look similar to this: { "type": "node", "request": "launch", - "name": "language-server Mocha Tests", - "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", + "name": "language-server Jest Tests", + "program": "${workspaceFolder}/node_modules/.bin/jest", "args": [ "-u", "bdd", @@ -108,7 +106,7 @@ When running this launch configuration in VS Code, it will stop on breakpoints y ### Test Coverage -100%\* Test Coverage is enforced for all productive code in this mono repo. +At least 90%\* Test Coverage is enforced for all productive code in this mono repo. - Specific statements/functions may be [excluded][ignore_coverage] from the report but the reason for that must specified in the source code. diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 000000000..a8d7b330a --- /dev/null +++ b/jest.config.js @@ -0,0 +1,55 @@ +const { join } = require("path"); + +module.exports = { + preset: "ts-jest", + testEnvironment: "node", + automock: false, + errorOnDeprecated: true, + notify: false, + notifyMode: "failure", + verbose: true, + testMatch: ["**/unit/**/?(*.)+(test).ts"], + transform: { + "^.+\\.ts?$": "ts-jest", + }, + collectCoverage: true, + snapshotFormat: { + escapeString: true, + printBasicPrototype: true, + }, + collectCoverageFrom: ["src/**/*.{ts,tsx}"], + coverageDirectory: "reports/test/unit/coverage", + coverageThreshold: { + global: { + branches: 90, + functions: 90, + lines: 90, + statements: 90, + }, + }, + + modulePathIgnorePatterns: [ + "/dist/", + "/node_modules/", + "/test/unit/samples/", + "/test/int/test-data/", + "/test/int/test-data-copy/", + ], + testPathIgnorePatterns: [ + "/node_modules/", + "/dist/", + "/lib/", + ], + transformIgnorePatterns: ["/node_modules/", "/node_modules/"], + reporters: [ + "default", + [ + "jest-sonar", + { + reportedFilePath: "relative", + relativeRootDir: "/../../../", + }, + ], + ], + setupFilesAfterEnv: ["../../jest.setup.js"], +}; diff --git a/jest.setup.js b/jest.setup.js new file mode 100644 index 000000000..bf6ed0d5c --- /dev/null +++ b/jest.setup.js @@ -0,0 +1,5 @@ +jest.setTimeout(120000); // 2 min + +// add all jest-extended matchers +const matchers = require("jest-extended"); +expect.extend(matchers); diff --git a/packages/nyc.config.js b/nyc.config.js similarity index 68% rename from packages/nyc.config.js rename to nyc.config.js index 68437aa3e..187bf8c02 100644 --- a/packages/nyc.config.js +++ b/nyc.config.js @@ -3,8 +3,8 @@ module.exports = { "check-coverage": true, all: true, // https://reflectoring.io/100-percent-test-coverage/ - branches: 100, - lines: 100, - functions: 100, - statements: 100, + branches: 95, + lines: 95, + functions: 95, + statements: 95, }; diff --git a/package.json b/package.json index fe59a0ad2..77070f4c6 100644 --- a/package.json +++ b/package.json @@ -44,9 +44,10 @@ "@types/chai": "4.2.14", "@types/deep-equal-in-any-order": "1.0.1", "@types/fs-extra": "9.0.11", + "@types/jest": "29.2.6", + "@types/jest-specific-snapshot": "0.5.5", "@types/klaw-sync": "6.0.0", "@types/lodash": "4.14.166", - "@types/mocha": "9.1.1", "@types/rimraf": "3.0.0", "@types/sinon": "9.0.10", "@types/sinon-chai": "3.2.5", @@ -64,11 +65,19 @@ "glob": "7.1.6", "husky": "8.0.1", "i18next": "19.0.2", + "jest": "29.5.0", + "jest-config": "29.5.0", + "jest-environment-node": "29.5.0", + "jest-environment-jsdom": "^29.5.0", + "jest-esm-transformer": "1.0.0", + "jest-extended": "3.2.3", + "jest-junit": "15.0.0", + "jest-sonar": "0.2.16", + "jest-specific-snapshot": "3.0.0", "klaw-sync": "6.0.0", "lerna": "6.0.3", "lint-staged": "10.5.3", "make-dir": "3.1.0", - "mocha": "10.0.0", "mock-fs": "^5.2.0", "npm-run-all": "4.1.5", "nyc": "15.1.0", @@ -76,10 +85,10 @@ "rimraf": "3.0.2", "shx": "0.3.3", "simple-git": "3.12.0", - "sinon": "9.2.3", - "sinon-chai": "3.5.0", + "ts-jest": "29.0.5", + "ts-node": "8.5.2", "source-map-support": "0.5.19", - "typescript": "3.9.7", + "typescript": "4.9.4", "esbuild": "0.17.12" }, "lint-staged": { @@ -99,5 +108,10 @@ "extends": [ "@commitlint/config-conventional" ] + }, + "jest": { + "setupFilesAfterEnv": [ + "jest-extended/all" + ] } } diff --git a/packages/binding-parser/CHANGELOG.md b/packages/binding-parser/CHANGELOG.md new file mode 100644 index 000000000..e0e17acd8 --- /dev/null +++ b/packages/binding-parser/CHANGELOG.md @@ -0,0 +1,7 @@ +# @ui5-language-assistant/binding-parser + +## 1.0.1 + +### Patch Changes + +- d8b77af: Provide a minimal code completion and syntax check for property binding info diff --git a/packages/binding-parser/jest.config.js b/packages/binding-parser/jest.config.js new file mode 100644 index 000000000..406cef575 --- /dev/null +++ b/packages/binding-parser/jest.config.js @@ -0,0 +1,15 @@ +const { join } = require("path"); +const defaultConfig = require("../../jest.config"); + +module.exports = { + ...defaultConfig, + globals: { + "ts-jest": { + tsconfig: join(__dirname, "tsconfig-test.json"), + diagnostics: { + // warnOnly: true, + exclude: /\.(spec|test)\.ts$/, + }, + }, + }, +}; diff --git a/packages/binding-parser/package.json b/packages/binding-parser/package.json new file mode 100644 index 000000000..c8046b6a8 --- /dev/null +++ b/packages/binding-parser/package.json @@ -0,0 +1,36 @@ +{ + "name": "@ui5-language-assistant/binding-parser", + "version": "1.0.1", + "private": true, + "description": "Parser for binding syntax", + "keywords": [], + "files": [ + ".reuse", + "LICENSES", + "lib/src", + "api.d.ts", + "src" + ], + "main": "lib/src/api.js", + "repository": "https://github.com/sap/ui5-language-assistant/", + "license": "Apache-2.0", + "dependencies": { + "chevrotain": "10.4.2", + "vscode-languageserver-types": "3.17.2" + }, + "devDependencies": { + "cross-env": "7.0.3" + }, + "scripts": { + "ci": "npm-run-all clean compile lint coverage", + "clean": "rimraf ./lib ./coverage ./nyc_output", + "compile": "yarn run clean && tsc -p .", + "compile:watch": "tsc -p . --watch", + "lint": "eslint . --ext .ts --max-warnings=0 --ignore-path=../../.gitignore", + "test": "jest --ci --forceExit --detectOpenHandles --maxWorkers=1 --coverage=false", + "coverage": "jest --ci --forceExit --detectOpenHandles --maxWorkers=1 --coverage=true", + "format:fix": "prettier --write \"**/*.@(js|ts|json|md)\" --ignore-path=.gitignore", + "test:update": "cross-env TEST_UPDATE=true npm-run-all compile test:update-data", + "test:update-data": "node scripts/updateTestData.js" + } +} diff --git a/packages/binding-parser/scripts/updateTestData.js b/packages/binding-parser/scripts/updateTestData.js new file mode 100644 index 000000000..8f9a4da9e --- /dev/null +++ b/packages/binding-parser/scripts/updateTestData.js @@ -0,0 +1,4 @@ +const { update } = require("../lib/test/unit/helper/update-test-data"); +update() + .then(() => console.log("Tests updated")) + .catch(console.error); diff --git a/packages/binding-parser/src/api.ts b/packages/binding-parser/src/api.ts new file mode 100644 index 000000000..5632b2881 --- /dev/null +++ b/packages/binding-parser/src/api.ts @@ -0,0 +1,60 @@ +export { parseBinding } from "./parser/index"; +export { BindingParserTypes } from "./types"; +export * from "./constant"; +export { + isAfterAdjacentRange, + isBefore, + isBeforeAdjacentRange, + positionContained, + rangeContained, +} from "./utils/position"; + +import { + Value, + PrimitiveValue, + CollectionValue, + StructureValue, +} from "./types/binding-parser"; + +export const isCollectionValue = ( + value: Value | undefined +): value is CollectionValue => { + if (!value) { + return false; + } + if ((value as CollectionValue).type === "collection-value") { + return true; + } + + return false; +}; + +export const isStructureValue = ( + value: Value | undefined +): value is StructureValue => { + if (!value) { + return false; + } + if ((value as StructureValue).type === "structure-value") { + return true; + } + + return false; +}; + +/** + * A value is considered as primitive if it is not structure or collection value + */ +export const isPrimitiveValue = ( + value: Value | undefined +): value is PrimitiveValue => { + if (!value) { + return false; + } + + if (isCollectionValue(value) || isStructureValue(value)) { + return false; + } + + return true; +}; diff --git a/packages/binding-parser/src/ast/binding-parser-visitor.ts b/packages/binding-parser/src/ast/binding-parser-visitor.ts new file mode 100644 index 000000000..45f8d5bd4 --- /dev/null +++ b/packages/binding-parser/src/ast/binding-parser-visitor.ts @@ -0,0 +1,211 @@ +import { CstNode, IToken } from "chevrotain"; +import type { Position } from "vscode-languageserver-types"; +import { + ARRAY, + BOOLEAN_VALUE, + COLON, + COMMA, + KEY, + LEFT_SQUARE, + LEFT_CURLY, + NULL_VALUE, + NUMBER_VALUE, + OBJECT, + OBJECT_ITEM, + RIGHT_SQUARE, + RIGHT_CURLY, + STRING_VALUE, + VALUE, + TEMPLATE, +} from "../constant"; +import { createToken, clearKey } from "../utils/create"; +import { locationToRange } from "../utils/range"; +import type { + StructureElement, + CollectionValue, + PrimitiveValue, + StructureValue, + Value, + VisitorParam, + CreateToken, + ObjectChildren, + Template, + BindingNode, + TemplateChildren, + TokenType, + ObjectItemChildren, + ValueChildren, + ArrayChildren, + Key, +} from "../types/binding-parser"; +import { bindingParser } from "../parser/binding-parser"; + +const BaseVisitor = bindingParser.getBaseCstVisitorConstructor(); +class BindingParserVisitor extends BaseVisitor { + startPosition?: Position; + constructor(startPosition?: Position) { + super(); + this.startPosition = startPosition; + this.validateVisitor(); + } + visit(cstNode: CstNode): BindingNode { + return super.visit(cstNode, { location: cstNode.location } as VisitorParam); + } + [TEMPLATE](node: TemplateChildren): Template { + const objects = node[OBJECT] ?? []; + const spaces = []; + const ast: Template = { + bindings: [], + spaces, + type: "template", + }; + for (const data of objects) { + const result = this.visit(data) as StructureValue; + ast.bindings.push(result); + } + return ast; + } + [OBJECT](node: ObjectChildren, param: VisitorParam): StructureValue { + const leftCurly = this.createToken(LEFT_CURLY, param, node[LEFT_CURLY]); + const rightCurly = this.createToken(RIGHT_CURLY, param, node[RIGHT_CURLY]); + const elements: StructureElement[] = []; + const data = node[OBJECT_ITEM] ?? []; + for (const element of data) { + const result = this.visit(element) as StructureElement; + if (result.key || result.colon || result.value) { + elements.push(result); + } + } + const range = locationToRange({ ...param, position: this.startPosition }); + const commas = this.getCommas(param, node[COMMA]); + return { + leftCurly, + elements, + rightCurly, + range, + commas, + type: "structure-value", + }; + } + [OBJECT_ITEM]( + node: ObjectItemChildren, + param: VisitorParam + ): StructureElement { + const keyToken = this.createToken( + KEY, + param, + node[KEY] ?? node[STRING_VALUE] + ); + let key; + if (keyToken) { + const text = keyToken?.text; + key = { ...keyToken, text: clearKey(text), originalText: text } as Key; + } + const colon = this.createToken(COLON, param, node[COLON]); + const value = this.isDefined(node[VALUE]) + ? (this.visit(node[VALUE][0]) as Value) + : undefined; + const range = locationToRange({ ...param, position: this.startPosition }); + return { key, colon, value, range, type: "structure-element" }; + } + [VALUE](node: ValueChildren, param: VisitorParam): Value | undefined { + const primitiveVal = this.primitiveValue(node, param); + if (primitiveVal) { + return primitiveVal; + } + + const structure = node[OBJECT]; + if (structure) { + /* istanbul ignore next */ + if (!structure.length) { + return; + } + return this.visit(structure[0]) as Value; + } + const data = node[ARRAY]; + if (data) { + if (!data.length) { + /* istanbul ignore next */ + return; + } + return this.visit(data[0]) as Value; + } + return; + } + primitiveValue(node: ValueChildren, param: VisitorParam): Value | undefined { + let data = node[STRING_VALUE]; + if (data) { + return this.createToken(STRING_VALUE, param, data); + } + data = node[NUMBER_VALUE]; + if (data) { + return this.createToken(NUMBER_VALUE, param, data); + } + data = node[NULL_VALUE]; + if (data) { + return this.createToken(NULL_VALUE, param, data); + } + data = node[BOOLEAN_VALUE]; + return this.createToken(BOOLEAN_VALUE, param, data); + } + [ARRAY](node: ArrayChildren, param: VisitorParam): CollectionValue { + const leftSquare = this.createToken(LEFT_SQUARE, param, node[LEFT_SQUARE]); + const rightSquare = this.createToken( + RIGHT_SQUARE, + param, + node[RIGHT_SQUARE] + ); + const commas = this.getCommas(param, node[COMMA]); + const elements: (PrimitiveValue | StructureValue)[] = []; + const data = node[VALUE] ?? []; + for (const element of data) { + const result = this.visit(element) as PrimitiveValue | StructureValue; + elements.push(result); + } + const range = locationToRange({ ...param, position: this.startPosition }); + return { + leftSquare, + elements, + rightSquare, + range, + commas, + type: "collection-value", + }; + } + createToken( + type: T, + param: VisitorParam, + node: IToken[] | undefined + ): CreateToken | undefined { + if (!this.isDefined(node)) { + return; + } + return createToken(node[0], type, { + ...param, + position: this.startPosition, + }); + } + getCommas( + param: VisitorParam, + nodes: IToken[] = [] + ): CreateToken[] { + const commas: CreateToken[] = []; + for (const comma of nodes) { + const commaToken = this.createToken(COMMA, param, [comma]); + if (commaToken) { + commas.push(commaToken); + } + } + return commas; + } + isDefined(node: T[] | undefined): node is T[] { + if (!node || node.length === 0) { + return false; + } + return true; + } +} + +export const bindingParserVisitor = ( + startPosition?: Position +): BindingParserVisitor => new BindingParserVisitor(startPosition); diff --git a/packages/binding-parser/src/ast/index.ts b/packages/binding-parser/src/ast/index.ts new file mode 100644 index 000000000..973d7fddd --- /dev/null +++ b/packages/binding-parser/src/ast/index.ts @@ -0,0 +1 @@ +export { bindingParserVisitor } from "./binding-parser-visitor"; diff --git a/packages/binding-parser/src/constant.ts b/packages/binding-parser/src/constant.ts new file mode 100644 index 000000000..50d6d29f1 --- /dev/null +++ b/packages/binding-parser/src/constant.ts @@ -0,0 +1,22 @@ +export const WHITE_SPACE = "white-space"; +export const SPECIAL_CHARS = "special-chars"; +export const RIGHT_CURLY = "right-curly"; +export const LEFT_CURLY = "left-curly"; +export const LEFT_SQUARE = "left-square"; +export const RIGHT_SQUARE = "right-square"; +export const KEY = "key"; +export const COLON = "colon"; +export const STRING_VALUE = "string-value"; +export const BOOLEAN_VALUE = "boolean-value"; +export const NUMBER_VALUE = "number-value"; +export const NULL_VALUE = "null-value"; +export const COMMA = "comma"; + +export const TEMPLATE = "template"; +export const OBJECT = "object"; +export const ARRAY = "array"; +export const OBJECT_ITEM = "object-item"; +export const VALUE = "value"; + +export const LEXER_ERROR = "lexer-error"; +export const PARSE_ERROR = "parse-error"; diff --git a/packages/binding-parser/src/lexer/index.ts b/packages/binding-parser/src/lexer/index.ts new file mode 100644 index 000000000..ebd40da29 --- /dev/null +++ b/packages/binding-parser/src/lexer/index.ts @@ -0,0 +1,8 @@ +import { Lexer } from "chevrotain"; +import { lexerDefinition } from "./token"; + +export { bindingParserTokenMap } from "./token"; +export const lexer = new Lexer(lexerDefinition, { + // Enable validation for debugging + skipValidations: true, +}); diff --git a/packages/binding-parser/src/lexer/token.ts b/packages/binding-parser/src/lexer/token.ts new file mode 100644 index 000000000..3b5ab4bdd --- /dev/null +++ b/packages/binding-parser/src/lexer/token.ts @@ -0,0 +1,117 @@ +import { createToken } from "chevrotain"; +import { + KEY, + STRING_VALUE, + BOOLEAN_VALUE, + COLON, + COMMA, + LEFT_SQUARE, + LEFT_CURLY, + NULL_VALUE, + NUMBER_VALUE, + RIGHT_SQUARE, + RIGHT_CURLY, + WHITE_SPACE, + SPECIAL_CHARS, + TEMPLATE, +} from "../constant"; + +const whiteSpace = createToken({ + name: WHITE_SPACE, + pattern: /\s+/, + // group: Lexer.SKIPPED, + line_breaks: true, +}); +const specialChars = createToken({ + name: SPECIAL_CHARS, + pattern: /(#|!|"|\$|%|&|'|\(|\)|\*|\+|-|\.|\/|;|<|=|>|\?|@|\\|\^|_|`|~|\||)+/, +}); + +const leftCurly = createToken({ + name: LEFT_CURLY, + pattern: /{/, + label: "{", +}); + +const rightCurly = createToken({ + name: RIGHT_CURLY, + pattern: /}/, + label: "}", +}); + +const leftBracket = createToken({ + name: LEFT_SQUARE, + pattern: /\[/, + label: "[", +}); +const rightBracket = createToken({ + name: RIGHT_SQUARE, + pattern: /]/, + label: "]", +}); +const key = createToken({ + name: KEY, + pattern: /[a-zA-Z$_][a-zA-Z0-9$_]*/, +}); +const colon = createToken({ + name: COLON, + pattern: /:/, + label: ":", +}); +const stringValue = createToken({ + name: STRING_VALUE, + pattern: /('|"|'|")(.*?)('|"|'|")/, +}); + +const booleanValue = createToken({ + name: BOOLEAN_VALUE, + pattern: /true|false/, +}); +const numberValue = createToken({ + name: NUMBER_VALUE, + pattern: /-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/, +}); + +const nullValue = createToken({ name: NULL_VALUE, pattern: /null/ }); + +const comma = createToken({ + name: COMMA, + pattern: /,/, + label: ",", +}); + +export const bindingParserTokenMap = { + whiteSpace, + numberValue, + leftCurly, + rightCurly, + leftBracket, + rightBracket, + comma, + colon, + booleanValue, + stringValue, + nullValue, + key, + specialChars, +}; +export const lexerDefinition = { + modes: { + [TEMPLATE]: [ + whiteSpace, + numberValue, + leftCurly, + rightCurly, + leftBracket, + rightBracket, + comma, + colon, + booleanValue, + stringValue, + nullValue, + key, + specialChars, + ], + }, + defaultMode: TEMPLATE, +}; diff --git a/packages/binding-parser/src/parser/binding-parser.ts b/packages/binding-parser/src/parser/binding-parser.ts new file mode 100644 index 000000000..5eeff0962 --- /dev/null +++ b/packages/binding-parser/src/parser/binding-parser.ts @@ -0,0 +1,144 @@ +import { CstParser } from "chevrotain"; +import type { CstNode, TokenType, IToken } from "chevrotain"; +import { ARRAY, OBJECT, OBJECT_ITEM, TEMPLATE, VALUE } from "../constant"; +import { bindingParserTokenMap as tokenMap } from "../lexer"; + +class BindingParser extends CstParser { + constructor() { + super(tokenMap, { + maxLookahead: 1, + recoveryEnabled: true, + nodeLocationTracking: "full", + // This could reduce 30-50% of the initialization time + // Enable validation for debugging + skipValidations: true, + }); + this.performSelfAnalysis(); + } + [TEMPLATE] = this.RULE(TEMPLATE, () => { + this.MANY(() => { + this.SUBRULE(this[OBJECT]); + }); + }); + + [OBJECT] = this.RULE(OBJECT, () => { + this.CONSUME(tokenMap.leftCurly); + this.OPTION(() => { + this.CUSTOM_MANY(tokenMap.rightCurly, this[OBJECT_ITEM]); + }); + this.CONSUME(tokenMap.rightCurly); + }); + + [OBJECT_ITEM] = this.RULE(OBJECT_ITEM, () => { + this.OR([ + { + GATE: (): boolean => this.LA(1).tokenType === tokenMap.colon, + ALT: (): void => { + // key is missing, but there is colon + this.CONSUME(tokenMap.colon); + this.SUBRULE(this[VALUE]); + }, + }, + { + GATE: (): boolean => + this.LA(1).tokenType === tokenMap.key && + (this.LA(2).tokenType === tokenMap.stringValue || + this.LA(2).tokenType === tokenMap.numberValue || + this.LA(2).tokenType === tokenMap.leftCurly || + this.LA(2).tokenType === tokenMap.leftBracket || + this.LA(2).tokenType === tokenMap.booleanValue || + this.LA(2).tokenType === tokenMap.nullValue), + ALT: (): void => { + // colon is missing, but there is key and value + this.CONSUME(tokenMap.key); + this.SUBRULE(this[VALUE]); + }, + }, + { + GATE: (): boolean => + this.LA(1).tokenType === tokenMap.stringValue && + (this.LA(2).tokenType === tokenMap.stringValue || + this.LA(2).tokenType === tokenMap.numberValue || + this.LA(2).tokenType === tokenMap.leftCurly || + this.LA(2).tokenType === tokenMap.leftBracket || + this.LA(2).tokenType === tokenMap.booleanValue || + this.LA(2).tokenType === tokenMap.nullValue), + ALT: (): void => { + // colon is missing, but there is key with quotes and value + this.CONSUME(tokenMap.stringValue); + this.SUBRULE(this[VALUE]); + }, + }, + { + GATE: (): boolean => this.LA(1).tokenType === tokenMap.stringValue, + ALT: (): void => { + // key with quotes + this.CONSUME(tokenMap.stringValue); + this.OPTION1(() => { + this.CONSUME(tokenMap.colon); + this.SUBRULE(this[VALUE]); + }); + }, + }, + { + ALT: (): void => { + this.CONSUME(tokenMap.key); + this.OPTION1(() => { + this.CONSUME(tokenMap.colon); + this.SUBRULE(this[VALUE]); + }); + }, + }, + ]); + }); + [VALUE] = this.RULE(VALUE, () => { + this.OR([ + { ALT: () => this.CONSUME(tokenMap.stringValue) }, + { ALT: () => this.CONSUME(tokenMap.numberValue) }, + { ALT: () => this.SUBRULE(this[OBJECT]) }, + { ALT: () => this.SUBRULE(this[ARRAY]) }, + { ALT: () => this.CONSUME(tokenMap.booleanValue) }, + { ALT: () => this.CONSUME(tokenMap.nullValue) }, + ]); + }); + + [ARRAY] = this.RULE(ARRAY, () => { + this.CONSUME(tokenMap.leftBracket); + this.OPTION(() => { + this.CUSTOM_MANY(tokenMap.rightBracket, this[VALUE]); + }); + this.CONSUME(tokenMap.rightBracket); + }); + + CUSTOM_MANY( + endToken: TokenType, + repetitionRule: (idxInCallingRule?: number, ...args: T[]) => CstNode + ): void { + this.MANY(() => { + // workaround for https://github.com/SAP/chevrotain/issues/1200 once it is fixed we can use empty alternative + this.OR([ + { + GATE: (): boolean => + this.LA(1).tokenType === tokenMap.comma && + (this.LA(2).tokenType === endToken || + this.LA(2).tokenType === tokenMap.comma), + ALT: (): IToken => this.CONSUME2(tokenMap.comma), + }, + { + GATE: (): boolean => + this.LA(1).tokenType === tokenMap.comma && + this.LA(2).tokenType !== endToken, + ALT: (): void => { + this.CONSUME3(tokenMap.comma); + this.SUBRULE(repetitionRule); + }, + }, + { + ALT: (): CstNode => this.SUBRULE1(repetitionRule), + }, + ]); + }); + } +} + +export const bindingParser = new BindingParser(); diff --git a/packages/binding-parser/src/parser/index.ts b/packages/binding-parser/src/parser/index.ts new file mode 100644 index 000000000..acc4f9450 --- /dev/null +++ b/packages/binding-parser/src/parser/index.ts @@ -0,0 +1,59 @@ +import type { + Template, + ParseResult, + SpecialChars, + WhiteSpaces, +} from "../types/binding-parser"; +import type { Position } from "vscode-languageserver-types"; +import { bindingParser } from "./binding-parser"; +import { lexer } from "../lexer"; +import { SPECIAL_CHARS, WHITE_SPACE } from "../constant"; +import { + createLexerErrors, + createToken, + createParseErrors, +} from "../utils/create"; +import { bindingParserVisitor } from "../ast"; + +export const parseBinding = ( + text: string, + position?: Position +): ParseResult => { + const { tokens, errors: lexErrors } = lexer.tokenize(text); + const spaceTokens = tokens.filter((t) => t.tokenType.name === WHITE_SPACE); + const spaces: WhiteSpaces[] = []; + for (const space of spaceTokens) { + spaces.push(createToken(space, WHITE_SPACE, { position })); + } + const knownTokens = tokens + .filter((t) => t.tokenType.name !== WHITE_SPACE) + .filter((t) => t.tokenType.name !== SPECIAL_CHARS); + bindingParser.input = knownTokens; + const cst = bindingParser.template(); + const parseErrors = bindingParser.errors; + const ast = bindingParserVisitor(position).visit(cst) as Template; + ast.spaces.push(...spaces); + /** + * Special chars are added to token so that chevrotain recognize them and provide correct location information. + * lets assume we have such input `{####path: }` and special token is not added to list of lexer token. + * In this case, position information start from `path` will have 3 chars less as chevrotain escape them. + * + * We add them as lexer error so that meaningful diagnostic is provided for end user + */ + const specialCharsToken = tokens.filter( + (t) => t.tokenType.name === SPECIAL_CHARS + ); + const specialChars: SpecialChars[] = []; + for (const specialChar of specialCharsToken) { + specialChars.push(createToken(specialChar, SPECIAL_CHARS, { position })); + } + return { + cst, + ast, + tokens, + errors: { + lexer: [...createLexerErrors(lexErrors, position), ...specialChars], + parse: createParseErrors(parseErrors, position), + }, + }; +}; diff --git a/packages/binding-parser/src/types/binding-parser.ts b/packages/binding-parser/src/types/binding-parser.ts new file mode 100644 index 000000000..139c2c031 --- /dev/null +++ b/packages/binding-parser/src/types/binding-parser.ts @@ -0,0 +1,206 @@ +import { Range } from "vscode-languageserver-types"; +import { IToken, CstNodeLocation, CstNode } from "chevrotain"; +import type { Position } from "vscode-languageserver-types"; +import { + ARRAY, + BOOLEAN_VALUE, + COLON, + COMMA, + KEY, + LEFT_CURLY, + LEFT_SQUARE, + LEXER_ERROR, + NULL_VALUE, + NUMBER_VALUE, + OBJECT, + OBJECT_ITEM, + PARSE_ERROR, + RIGHT_CURLY, + RIGHT_SQUARE, + SPECIAL_CHARS, + STRING_VALUE, + TEMPLATE, + VALUE, + WHITE_SPACE, +} from "../constant"; + +export interface VisitorParam { + position?: Position; + location?: CstNodeLocation; +} +export type TokenType = + | typeof WHITE_SPACE + | typeof SPECIAL_CHARS + | typeof COLON + | typeof KEY + | typeof LEFT_CURLY + | typeof RIGHT_CURLY + | typeof LEFT_SQUARE + | typeof RIGHT_SQUARE + | typeof STRING_VALUE + | typeof NULL_VALUE + | typeof NUMBER_VALUE + | typeof COMMA + | typeof BOOLEAN_VALUE + | typeof PARSE_ERROR; + +export interface Base { + text: string; + range: Range; +} + +export interface Comma extends Base { + type: typeof COMMA; +} +export interface WhiteSpaces extends Base { + type: typeof WHITE_SPACE; +} +export interface SpecialChars extends Base { + type: typeof SPECIAL_CHARS; +} +export interface LeftCurly extends Base { + type: typeof LEFT_CURLY; +} +export interface RightCurly extends Base { + type: typeof RIGHT_CURLY; +} +export interface LeftSquare extends Base { + type: typeof LEFT_SQUARE; +} +export interface RightSquare extends Base { + type: typeof RIGHT_SQUARE; +} +export interface Key extends Base { + type: typeof KEY; + originalText: string; +} +export interface Colon extends Base { + type: typeof COLON; +} +export type PrimitiveValueType = + | typeof STRING_VALUE + | typeof NUMBER_VALUE + | typeof NULL_VALUE + | typeof BOOLEAN_VALUE; + +export interface PrimitiveValue extends Base { + type: PrimitiveValueType; +} + +export interface LexerError extends Base { + type: typeof LEXER_ERROR | typeof SPECIAL_CHARS; +} +export interface ParseErrorBase extends Base { + type: typeof PARSE_ERROR; + tokenTypeName: string; +} + +export interface ParseError extends ParseErrorBase { + merged: ParseErrorBase[]; + previousToken?: ParseErrorBase; + message: string; +} + +export interface CollectionValue { + leftSquare?: LeftSquare; + elements: (PrimitiveValue | StructureValue)[]; + range?: Range; // range which include left bracket, element and right bracket + rightSquare?: RightSquare; + commas?: Comma[]; + type: "collection-value"; +} +export type Value = PrimitiveValue | StructureValue | CollectionValue; + +export interface StructureElement { + key?: Key; + colon?: Colon; + value?: Value; + range?: Range; // range of this element which include key, colon and value + type: "structure-element"; +} + +export interface StructureValue { + leftCurly?: LeftCurly; + rightCurly?: RightCurly; + elements: StructureElement[]; + range?: Range; // range which include left bracket, element and right bracket, + commas?: Comma[]; + type: "structure-value"; +} +export interface Template { + bindings: StructureValue[]; + type: "template"; + spaces: WhiteSpaces[]; +} + +export interface ParseResult { + cst: CstNode; + ast: Template; + tokens: IToken[]; + errors: { + lexer: LexerError[]; + parse: ParseError[]; + }; +} + +export interface CreateToken { + type: T; + text: string; + range: Range; +} + +export type TemplateChildren = { + [OBJECT]?: ObjectCstNode[]; +}; +export interface TemplateCstNode extends CstNode { + name: typeof TEMPLATE; + children: TemplateChildren; +} + +export type ObjectChildren = { + [LEFT_CURLY]?: IToken[]; + [RIGHT_CURLY]?: IToken[]; + [OBJECT_ITEM]?: ObjectItemCstNode[]; + [COMMA]?: IToken[]; +}; + +export interface ObjectCstNode extends CstNode { + name: typeof OBJECT; + children: ObjectChildren; +} + +export type ArrayChildren = { + [LEFT_SQUARE]?: IToken[]; + [RIGHT_SQUARE]?: IToken[]; + [VALUE]?: ValueCstNode[]; + [COMMA]?: IToken[]; +}; +export interface ArrayCstNode extends CstNode { + name: typeof ARRAY; + children: ArrayChildren; +} + +export type ObjectItemChildren = { + [KEY]?: IToken[]; + [COLON]?: IToken[]; + [VALUE]?: ValueCstNode[]; +}; +export interface ObjectItemCstNode extends CstNode { + name: typeof OBJECT_ITEM; + children: ObjectItemChildren; +} + +export type ValueChildren = { + [STRING_VALUE]?: IToken[]; + [NUMBER_VALUE]?: IToken[]; + [OBJECT]?: ObjectCstNode[]; + [ARRAY]?: ArrayCstNode[]; + [BOOLEAN_VALUE]?: IToken[]; + [NULL_VALUE]?: IToken[]; +}; +export interface ValueCstNode extends CstNode { + name: typeof VALUE; + children: ValueChildren; +} + +export type BindingNode = Template | StructureElement | Value | CollectionValue; diff --git a/packages/binding-parser/src/types/index.ts b/packages/binding-parser/src/types/index.ts new file mode 100644 index 000000000..a25a07d27 --- /dev/null +++ b/packages/binding-parser/src/types/index.ts @@ -0,0 +1 @@ +export * as BindingParserTypes from "./binding-parser"; diff --git a/packages/binding-parser/src/utils/create.ts b/packages/binding-parser/src/utils/create.ts new file mode 100644 index 000000000..e717b4370 --- /dev/null +++ b/packages/binding-parser/src/utils/create.ts @@ -0,0 +1,135 @@ +import { + IToken, + ILexingError, + IRecognitionException, + MismatchedTokenException, + NoViableAltException, +} from "chevrotain"; +import { LEXER_ERROR, PARSE_ERROR } from "../constant"; +import type { Position } from "vscode-languageserver-types"; +import type { + CreateToken, + LexerError, + TokenType, + ParseError, + ParseErrorBase, + VisitorParam, +} from "../types/binding-parser"; +import { getLexerRange, getRange } from "./range"; + +export const createToken = ( + token: IToken, + type: T, + param?: VisitorParam +): CreateToken => { + const text = token.image; + const range = getRange(token, param); + return { + type, + text, + range, + }; +}; + +export const createLexerErrors = ( + node: ILexingError[], + position?: Position +): LexerError[] => { + const result: LexerError[] = []; + for (const item of node) { + const range = getLexerRange(item, position); + result.push({ + range, + text: "", + type: LEXER_ERROR, + }); + } + return result; +}; + +export const createParseErrors = ( + nodes: ( + | IRecognitionException + | MismatchedTokenException + | NoViableAltException + )[], + position?: Position +): ParseError[] => { + const result: ParseError[] = []; + let tokens: ParseErrorBase[] = []; + for (const item of nodes) { + let node = createToken(item.token, PARSE_ERROR, { position }); + tokens.push({ ...node, tokenTypeName: item.token.tokenType.name }); + for (const resync of item.resyncedTokens) { + node = createToken(resync, PARSE_ERROR, { position }); + tokens.push({ ...node, tokenTypeName: resync.tokenType.name }); + } + const itemWithPreviousToken = item as + | MismatchedTokenException + | NoViableAltException; + let previousToken: ParseErrorBase | undefined; + if (itemWithPreviousToken.previousToken) { + node = createToken(itemWithPreviousToken.previousToken, PARSE_ERROR, { + position, + }); + previousToken = { + ...node, + tokenTypeName: itemWithPreviousToken.previousToken.tokenType.name, + }; + } + + if (tokens.length === 1) { + result.push({ + type: PARSE_ERROR, + range: tokens[0].range, + text: tokens[0].text, + merged: tokens, + tokenTypeName: tokens[0].tokenTypeName, + previousToken, + message: item.message, + }); + // rest tokens + tokens = []; + continue; + } + const [first] = tokens; + const last = tokens[tokens.length - 1]; + let text = ""; + let tokenTypeName = ""; + tokens.forEach((t) => { + text += t.text; + if (tokenTypeName) { + tokenTypeName = `${tokenTypeName}|${t.tokenTypeName}`; + } else { + tokenTypeName = t.tokenTypeName; + } + }); + result.push({ + type: PARSE_ERROR, + range: { + start: first.range.start, + end: last.range.end, + }, + text, + merged: tokens, + tokenTypeName, + previousToken, + message: item.message, + }); + // rest token + tokens = []; + } + return result; +}; + +/** + * Change key from + * a. 'key' + * b. "key" + * c. 'key' + * d. "key" + * to key without any quotes + */ +export const clearKey = (key = ""): string => { + return key.split(/'|"|'|"/).filter((i) => !!i)[0] ?? ""; +}; diff --git a/packages/binding-parser/src/utils/position.ts b/packages/binding-parser/src/utils/position.ts new file mode 100644 index 000000000..b5b66439c --- /dev/null +++ b/packages/binding-parser/src/utils/position.ts @@ -0,0 +1,85 @@ +import { Range, Position } from "vscode-languageserver-types"; +/** + * Check if the second range `e.g b` is within the first range `e.g a` + */ +export function rangeContained( + a: Range, + b: Range, + includeEqual = false +): boolean { + return ( + isBefore(a.start, b.start, includeEqual) && + isBefore(b.end, a.end, includeEqual) + ); +} +/** + * checks if position is contained in range + */ +export function positionContained( + range: Range | undefined, + position: Position +): range is Range { + return ( + range !== undefined && + !isBefore(position, range.start, false) && + isBefore(position, range.end, true) + ); +} + +/** + * Checks if position1 is before position2 + */ +export function isBefore( + pos1: Position, + pos2: Position, + includeEqual = false +): boolean { + if (pos1.line < pos2.line) { + return true; + } + if (pos1.line > pos2.line) { + return false; + } + if (includeEqual) { + return pos1.character <= pos2.character; + } + + return pos1.character < pos2.character; +} + +/** + * Checks if range1 is positioned before adjacent range2 + */ +export const isBeforeAdjacentRange = ( + range1?: Range, + range2?: Range +): boolean => { + if (!range1 || !range2) { + return false; + } + if ( + range1.end.line === range2.start.line && + range1.end.character === range2.start.character + ) { + return true; + } + return false; +}; +/** + * Checks if range1 is positioned after adjacent range2 + */ +export const isAfterAdjacentRange = ( + range1?: Range, + range2?: Range +): boolean => { + if (!range1 || !range2) { + return false; + } + if ( + range1.start.line === range2.end.line && + range1.start.character === range2.end.character + ) { + return true; + } + return false; +}; diff --git a/packages/binding-parser/src/utils/range.ts b/packages/binding-parser/src/utils/range.ts new file mode 100644 index 000000000..6ce358948 --- /dev/null +++ b/packages/binding-parser/src/utils/range.ts @@ -0,0 +1,83 @@ +import { IToken, ILexingError, CstNodeLocation } from "chevrotain"; +import { VisitorParam } from "../types/binding-parser"; +import { Position, Range } from "vscode-languageserver-types"; + +const isNaNOrUndefined = (value: undefined | number): boolean => { + if (value === undefined) { + return true; + } + return isNaN(value); +}; +const isNumber = (value: undefined | number): value is number => { + const result = isNaNOrUndefined(value); + if (result) { + return false; + } + return true; +}; + +const adjustPosition = (position: Position, offset: Position): Position => + Position.create( + position.line + offset.line, + position.line === 0 + ? position.character + offset.character + : position.character + ); + +export const getLexerRange = ( + node: ILexingError, + startPosition?: Position +): Range => { + const startLine = isNumber(node.line) ? node.line - 1 : 0; + const startChar = isNumber(node.column) ? node.column - 1 : 0; + const start = Position.create(startLine, startChar); + + const endLine = isNumber(node.line) ? node.line - 1 : 0; + const endChar = startChar + node.length; + const end = Position.create(endLine, endChar); + if (startPosition) { + return Range.create( + adjustPosition(start, startPosition), + adjustPosition(end, startPosition) + ); + } + + return Range.create(start, end); +}; + +const createRange = (item: CstNodeLocation | IToken) => + Range.create( + isNumber(item.startLine) ? item.startLine - 1 : 0, + isNumber(item.startColumn) ? item.startColumn - 1 : 0, + isNumber(item.endLine) ? item.endLine - 1 : 0, + isNumber(item.endColumn) ? item.endColumn : 0 + ); + +export const getRange = (token: IToken, param?: VisitorParam): Range => { + const startPosition = param?.position; + const { start, end } = createRange(token); + if (startPosition) { + return Range.create( + adjustPosition(start, startPosition), + adjustPosition(end, startPosition) + ); + } + + return { start, end }; +}; + +export const locationToRange = (param?: VisitorParam): Range | undefined => { + const location = param?.location; + if (!location) { + return; + } + const startPosition = param?.position; + const { start, end } = createRange(location); + if (startPosition) { + return Range.create( + adjustPosition(start, startPosition), + adjustPosition(end, startPosition) + ); + } + return { start, end }; +}; diff --git a/packages/binding-parser/test/unit/api.test.ts b/packages/binding-parser/test/unit/api.test.ts new file mode 100644 index 000000000..e8ac3ae29 --- /dev/null +++ b/packages/binding-parser/test/unit/api.test.ts @@ -0,0 +1,69 @@ +import { + isPrimitiveValue, + isCollectionValue, + isStructureValue, + parseBinding, +} from "../../src/api"; + +describe("api", () => { + describe("isPrimitiveValue", () => { + it("false [undefined]", () => { + const result = isPrimitiveValue(undefined); + expect(result).toBeFalse(); + }); + it("false [isCollectionValue(value)]", () => { + const { ast } = parseBinding("{key: []}"); + const value = ast.bindings[0].elements[0].value; + const result = isPrimitiveValue(value); + expect(result).toBeFalse(); + }); + it("false [isStructureValue(value)]", () => { + const { ast } = parseBinding("{key: {} }"); + const value = ast.bindings[0].elements[0].value; + const result = isPrimitiveValue(value); + expect(result).toBeFalse(); + }); + it("true", () => { + const { ast } = parseBinding("{key: 123 }"); + const value = ast.bindings[0].elements[0].value; + const result = isPrimitiveValue(value); + expect(result).toBeTrue(); + }); + }); + describe("isCollectionValue", () => { + it("false [undefined]", () => { + const result = isCollectionValue(undefined); + expect(result).toBeFalse(); + }); + it("false [type !== collection-value]", () => { + const { ast } = parseBinding("{key: {} }"); + const value = ast.bindings[0].elements[0].value; + const result = isCollectionValue(value); + expect(result).toBeFalse(); + }); + it("true [type === collection-value]", () => { + const { ast } = parseBinding("{key: [] }"); + const value = ast.bindings[0].elements[0].value; + const result = isCollectionValue(value); + expect(result).toBeTrue(); + }); + }); + describe("isStructureValue", () => { + it("false [undefined]", () => { + const result = isStructureValue(undefined); + expect(result).toBeFalse(); + }); + it("false [type !== structure-value]", () => { + const { ast } = parseBinding("{key: [] }"); + const value = ast.bindings[0].elements[0].value; + const result = isStructureValue(value); + expect(result).toBeFalse(); + }); + it("true [type === structure-value]", () => { + const { ast } = parseBinding("{key: {} }"); + const value = ast.bindings[0].elements[0].value; + const result = isStructureValue(value); + expect(result).toBeTrue(); + }); + }); +}); diff --git a/packages/binding-parser/test/unit/data/colon/colon-only/ast.json b/packages/binding-parser/test/unit/data/colon/colon-only/ast.json new file mode 100644 index 000000000..8ac4c9d0c --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/colon-only/ast.json @@ -0,0 +1,34 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": "undefined", + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,1)..(0,2)]" + }, + "value": "undefined", + "range": "[(0,1)..(0,2)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,2)..(0,3)]" + }, + "range": "[(0,0)..(0,3)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/colon/colon-only/cst.json b/packages/binding-parser/test/unit/data/colon/colon-only/cst.json new file mode 100644 index 000000000..e32ddfc9b --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/colon-only/cst.json @@ -0,0 +1,67 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "colon": [ + { + "image": ":", + "startColumn": 2, + "endColumn": 2, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": {}, + "location": { + "startColumn": -1, + "endColumn": -1 + }, + "recoveredNode": true + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 2 + }, + "recoveredNode": true + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 3, + "endColumn": 3, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 3 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 3 + } +} diff --git a/packages/binding-parser/test/unit/data/colon/colon-only/input.txt b/packages/binding-parser/test/unit/data/colon/colon-only/input.txt new file mode 100644 index 000000000..d4656fdee --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/colon-only/input.txt @@ -0,0 +1 @@ +{:} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/colon/colon-only/lexer-errors.json b/packages/binding-parser/test/unit/data/colon/colon-only/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/colon-only/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/colon/colon-only/parse-errors.json b/packages/binding-parser/test/unit/data/colon/colon-only/parse-errors.json new file mode 100644 index 000000000..1a20ca5e7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/colon-only/parse-errors.json @@ -0,0 +1,23 @@ +[ + { + "type": "parse-error", + "range": "[(0,2)..(0,3)]", + "text": "}", + "merged": [ + { + "type": "parse-error", + "text": "}", + "range": "[(0,2)..(0,3)]", + "tokenTypeName": "right-curly" + } + ], + "tokenTypeName": "right-curly", + "previousToken": { + "type": "parse-error", + "text": ":", + "range": "[(0,1)..(0,2)]", + "tokenTypeName": "colon" + }, + "message": "Expecting: one of these possible Token sequences:\n 1. [string-value]\n 2. [number-value]\n 3. [{]\n 4. [[]\n 5. [boolean-value]\n 6. [null-value]\nbut found: '}'" + } +] diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/boolean-value/ast.json b/packages/binding-parser/test/unit/data/colon/missing-colon/boolean-value/ast.json new file mode 100644 index 000000000..208cc2e8b --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/boolean-value/ast.json @@ -0,0 +1,45 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,1)..(0,4)]", + "originalText": "key" + }, + "colon": "undefined", + "value": { + "type": "boolean-value", + "text": "true", + "range": "[(0,5)..(0,9)]" + }, + "range": "[(0,1)..(0,9)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,9)..(0,10)]" + }, + "range": "[(0,0)..(0,10)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,4)..(0,5)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/boolean-value/cst.json b/packages/binding-parser/test/unit/data/colon/missing-colon/boolean-value/cst.json new file mode 100644 index 000000000..3dd959dc6 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/boolean-value/cst.json @@ -0,0 +1,74 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 2, + "endColumn": 4, + "tokenTypeName": "key" + } + ], + "value": [ + { + "name": "value", + "children": { + "boolean-value": [ + { + "image": "true", + "startColumn": 6, + "endColumn": 9, + "tokenTypeName": "boolean-value" + } + ] + }, + "location": { + "startColumn": 6, + "endColumn": 9 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 9 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 10, + "endColumn": 10, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 10 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 10 + } +} diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/boolean-value/input.txt b/packages/binding-parser/test/unit/data/colon/missing-colon/boolean-value/input.txt new file mode 100644 index 000000000..89d6862a1 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/boolean-value/input.txt @@ -0,0 +1 @@ +{key true} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/boolean-value/lexer-errors.json b/packages/binding-parser/test/unit/data/colon/missing-colon/boolean-value/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/boolean-value/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/boolean-value/parse-errors.json b/packages/binding-parser/test/unit/data/colon/missing-colon/boolean-value/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/boolean-value/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/colection-value/ast.json b/packages/binding-parser/test/unit/data/colon/missing-colon/colection-value/ast.json new file mode 100644 index 000000000..8fadca418 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/colection-value/ast.json @@ -0,0 +1,109 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "parts", + "range": "[(0,2)..(0,7)]", + "originalText": "parts" + }, + "colon": "undefined", + "value": { + "leftSquare": { + "type": "left-square", + "text": "[", + "range": "[(0,8)..(0,9)]" + }, + "elements": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,9)..(0,10)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "path", + "range": "[(0,10)..(0,14)]", + "originalText": "path" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,14)..(0,15)]" + }, + "value": { + "type": "string-value", + "text": "''", + "range": "[(0,16)..(0,18)]" + }, + "range": "[(0,10)..(0,18)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,18)..(0,19)]" + }, + "range": "[(0,9)..(0,19)]", + "commas": [], + "type": "structure-value" + } + ], + "rightSquare": { + "type": "right-square", + "text": "]", + "range": "[(0,19)..(0,20)]" + }, + "range": "[(0,8)..(0,20)]", + "commas": [], + "type": "collection-value" + }, + "range": "[(0,2)..(0,20)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,21)..(0,22)]" + }, + "range": "[(0,0)..(0,22)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,1)..(0,2)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,7)..(0,8)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,15)..(0,16)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,20)..(0,21)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/colection-value/cst.json b/packages/binding-parser/test/unit/data/colon/missing-colon/colection-value/cst.json new file mode 100644 index 000000000..336a0d9a2 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/colection-value/cst.json @@ -0,0 +1,177 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "parts", + "startColumn": 3, + "endColumn": 7, + "tokenTypeName": "key" + } + ], + "value": [ + { + "name": "value", + "children": { + "array": [ + { + "name": "array", + "children": { + "left-square": [ + { + "image": "[", + "startColumn": 9, + "endColumn": 9, + "tokenTypeName": "left-square" + } + ], + "value": [ + { + "name": "value", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 10, + "endColumn": 10, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "path", + "startColumn": 11, + "endColumn": 14, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 15, + "endColumn": 15, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "''", + "startColumn": 17, + "endColumn": 18, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 17, + "endColumn": 18 + } + } + ] + }, + "location": { + "startColumn": 11, + "endColumn": 18 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 19, + "endColumn": 19, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 10, + "endColumn": 19 + } + } + ] + }, + "location": { + "startColumn": 10, + "endColumn": 19 + } + } + ], + "right-square": [ + { + "image": "]", + "startColumn": 20, + "endColumn": 20, + "tokenTypeName": "right-square" + } + ] + }, + "location": { + "startColumn": 9, + "endColumn": 20 + } + } + ] + }, + "location": { + "startColumn": 9, + "endColumn": 20 + } + } + ] + }, + "location": { + "startColumn": 3, + "endColumn": 20 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 22, + "endColumn": 22, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 22 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 22 + } +} diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/colection-value/input.txt b/packages/binding-parser/test/unit/data/colon/missing-colon/colection-value/input.txt new file mode 100644 index 000000000..abc11f81a --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/colection-value/input.txt @@ -0,0 +1 @@ +{ parts [{path: ''}] } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/colection-value/lexer-errors.json b/packages/binding-parser/test/unit/data/colon/missing-colon/colection-value/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/colection-value/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/colection-value/parse-errors.json b/packages/binding-parser/test/unit/data/colon/missing-colon/colection-value/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/colection-value/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/null-value/ast.json b/packages/binding-parser/test/unit/data/colon/missing-colon/null-value/ast.json new file mode 100644 index 000000000..53324729b --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/null-value/ast.json @@ -0,0 +1,45 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,1)..(0,4)]", + "originalText": "key" + }, + "colon": "undefined", + "value": { + "type": "null-value", + "text": "null", + "range": "[(0,5)..(0,9)]" + }, + "range": "[(0,1)..(0,9)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,9)..(0,10)]" + }, + "range": "[(0,0)..(0,10)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,4)..(0,5)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/null-value/cst.json b/packages/binding-parser/test/unit/data/colon/missing-colon/null-value/cst.json new file mode 100644 index 000000000..16fe76752 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/null-value/cst.json @@ -0,0 +1,74 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 2, + "endColumn": 4, + "tokenTypeName": "key" + } + ], + "value": [ + { + "name": "value", + "children": { + "null-value": [ + { + "image": "null", + "startColumn": 6, + "endColumn": 9, + "tokenTypeName": "null-value" + } + ] + }, + "location": { + "startColumn": 6, + "endColumn": 9 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 9 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 10, + "endColumn": 10, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 10 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 10 + } +} diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/null-value/input.txt b/packages/binding-parser/test/unit/data/colon/missing-colon/null-value/input.txt new file mode 100644 index 000000000..b5e9a8573 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/null-value/input.txt @@ -0,0 +1 @@ +{key null} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/null-value/lexer-errors.json b/packages/binding-parser/test/unit/data/colon/missing-colon/null-value/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/null-value/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/null-value/parse-errors.json b/packages/binding-parser/test/unit/data/colon/missing-colon/null-value/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/null-value/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/number-value/ast.json b/packages/binding-parser/test/unit/data/colon/missing-colon/number-value/ast.json new file mode 100644 index 000000000..e2d5d9f9f --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/number-value/ast.json @@ -0,0 +1,59 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,2)..(0,5)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,5)..(0,6)]" + }, + "value": { + "type": "number-value", + "text": "123", + "range": "[(0,7)..(0,10)]" + }, + "range": "[(0,2)..(0,10)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,11)..(0,12)]" + }, + "range": "[(0,0)..(0,12)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,1)..(0,2)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,6)..(0,7)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,10)..(0,11)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/number-value/cst.json b/packages/binding-parser/test/unit/data/colon/missing-colon/number-value/cst.json new file mode 100644 index 000000000..8a16a32d3 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/number-value/cst.json @@ -0,0 +1,82 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 3, + "endColumn": 5, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 6, + "endColumn": 6, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "number-value": [ + { + "image": "123", + "startColumn": 8, + "endColumn": 10, + "tokenTypeName": "number-value" + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 10 + } + } + ] + }, + "location": { + "startColumn": 3, + "endColumn": 10 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 12, + "endColumn": 12, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 12 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 12 + } +} diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/number-value/input.txt b/packages/binding-parser/test/unit/data/colon/missing-colon/number-value/input.txt new file mode 100644 index 000000000..7d3c5db01 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/number-value/input.txt @@ -0,0 +1 @@ +{ key: 123 } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/number-value/lexer-errors.json b/packages/binding-parser/test/unit/data/colon/missing-colon/number-value/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/number-value/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/number-value/parse-errors.json b/packages/binding-parser/test/unit/data/colon/missing-colon/number-value/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/number-value/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/string-value/ast.json b/packages/binding-parser/test/unit/data/colon/missing-colon/string-value/ast.json new file mode 100644 index 000000000..0b4e019fa --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/string-value/ast.json @@ -0,0 +1,45 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,1)..(0,4)]", + "originalText": "key" + }, + "colon": "undefined", + "value": { + "type": "string-value", + "text": "'value'", + "range": "[(0,5)..(0,12)]" + }, + "range": "[(0,1)..(0,12)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,12)..(0,13)]" + }, + "range": "[(0,0)..(0,13)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,4)..(0,5)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/string-value/cst.json b/packages/binding-parser/test/unit/data/colon/missing-colon/string-value/cst.json new file mode 100644 index 000000000..30b5d8296 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/string-value/cst.json @@ -0,0 +1,74 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 2, + "endColumn": 4, + "tokenTypeName": "key" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'value'", + "startColumn": 6, + "endColumn": 12, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 6, + "endColumn": 12 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 12 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 13, + "endColumn": 13, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 13 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 13 + } +} diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/string-value/input.txt b/packages/binding-parser/test/unit/data/colon/missing-colon/string-value/input.txt new file mode 100644 index 000000000..bd3017052 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/string-value/input.txt @@ -0,0 +1 @@ +{key 'value'} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/string-value/lexer-errors.json b/packages/binding-parser/test/unit/data/colon/missing-colon/string-value/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/string-value/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/string-value/parse-errors.json b/packages/binding-parser/test/unit/data/colon/missing-colon/string-value/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/string-value/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/structure-value/ast.json b/packages/binding-parser/test/unit/data/colon/missing-colon/structure-value/ast.json new file mode 100644 index 000000000..ad68bfb8a --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/structure-value/ast.json @@ -0,0 +1,66 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,2)..(0,5)]", + "originalText": "key" + }, + "colon": "undefined", + "value": { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,6)..(0,7)]" + }, + "elements": [], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,7)..(0,8)]" + }, + "range": "[(0,6)..(0,8)]", + "commas": [], + "type": "structure-value" + }, + "range": "[(0,2)..(0,8)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,9)..(0,10)]" + }, + "range": "[(0,0)..(0,10)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,1)..(0,2)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,5)..(0,6)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,8)..(0,9)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/structure-value/cst.json b/packages/binding-parser/test/unit/data/colon/missing-colon/structure-value/cst.json new file mode 100644 index 000000000..dea5cbc2c --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/structure-value/cst.json @@ -0,0 +1,93 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 3, + "endColumn": 5, + "tokenTypeName": "key" + } + ], + "value": [ + { + "name": "value", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 7, + "endColumn": 7, + "tokenTypeName": "left-curly" + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 8, + "endColumn": 8, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 7, + "endColumn": 8 + } + } + ] + }, + "location": { + "startColumn": 7, + "endColumn": 8 + } + } + ] + }, + "location": { + "startColumn": 3, + "endColumn": 8 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 10, + "endColumn": 10, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 10 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 10 + } +} diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/structure-value/input.txt b/packages/binding-parser/test/unit/data/colon/missing-colon/structure-value/input.txt new file mode 100644 index 000000000..e86933eb1 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/structure-value/input.txt @@ -0,0 +1 @@ +{ key {} } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/structure-value/lexer-errors.json b/packages/binding-parser/test/unit/data/colon/missing-colon/structure-value/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/structure-value/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/colon/missing-colon/structure-value/parse-errors.json b/packages/binding-parser/test/unit/data/colon/missing-colon/structure-value/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/missing-colon/structure-value/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/colon/too-many-colons/ast.json b/packages/binding-parser/test/unit/data/colon/too-many-colons/ast.json new file mode 100644 index 000000000..d8fffc0bf --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/too-many-colons/ast.json @@ -0,0 +1,82 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,1)..(0,4)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,4)..(0,5)]" + }, + "value": "undefined", + "range": "[(0,1)..(0,5)]", + "type": "structure-element" + }, + { + "key": "undefined", + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,5)..(0,6)]" + }, + "value": "undefined", + "range": "[(0,5)..(0,6)]", + "type": "structure-element" + }, + { + "key": "undefined", + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,6)..(0,7)]" + }, + "value": "undefined", + "range": "[(0,6)..(0,7)]", + "type": "structure-element" + }, + { + "key": "undefined", + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,7)..(0,8)]" + }, + "value": { + "type": "string-value", + "text": "'value'", + "range": "[(0,9)..(0,16)]" + }, + "range": "[(0,7)..(0,16)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,16)..(0,17)]" + }, + "range": "[(0,0)..(0,17)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,8)..(0,9)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/colon/too-many-colons/cst.json b/packages/binding-parser/test/unit/data/colon/too-many-colons/cst.json new file mode 100644 index 000000000..6dfd88fa5 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/too-many-colons/cst.json @@ -0,0 +1,169 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 2, + "endColumn": 4, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 5, + "endColumn": 5, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": {}, + "location": { + "startColumn": -1, + "endColumn": -1 + }, + "recoveredNode": true + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 5 + }, + "recoveredNode": true + }, + { + "name": "object-item", + "children": { + "colon": [ + { + "image": ":", + "startColumn": 6, + "endColumn": 6, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": {}, + "location": { + "startColumn": -1, + "endColumn": -1 + }, + "recoveredNode": true + } + ] + }, + "location": { + "startColumn": 6, + "endColumn": 6 + }, + "recoveredNode": true + }, + { + "name": "object-item", + "children": { + "colon": [ + { + "image": ":", + "startColumn": 7, + "endColumn": 7, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": {}, + "location": { + "startColumn": -1, + "endColumn": -1 + }, + "recoveredNode": true + } + ] + }, + "location": { + "startColumn": 7, + "endColumn": 7 + }, + "recoveredNode": true + }, + { + "name": "object-item", + "children": { + "colon": [ + { + "image": ":", + "startColumn": 8, + "endColumn": 8, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'value'", + "startColumn": 10, + "endColumn": 16, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 10, + "endColumn": 16 + } + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 16 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 17, + "endColumn": 17, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 17 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 17 + } +} diff --git a/packages/binding-parser/test/unit/data/colon/too-many-colons/input.txt b/packages/binding-parser/test/unit/data/colon/too-many-colons/input.txt new file mode 100644 index 000000000..98c630d60 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/too-many-colons/input.txt @@ -0,0 +1 @@ +{key:::: 'value'} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/colon/too-many-colons/lexer-errors.json b/packages/binding-parser/test/unit/data/colon/too-many-colons/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/too-many-colons/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/colon/too-many-colons/parse-errors.json b/packages/binding-parser/test/unit/data/colon/too-many-colons/parse-errors.json new file mode 100644 index 000000000..6ee18b8f1 --- /dev/null +++ b/packages/binding-parser/test/unit/data/colon/too-many-colons/parse-errors.json @@ -0,0 +1,65 @@ +[ + { + "type": "parse-error", + "range": "[(0,5)..(0,6)]", + "text": ":", + "merged": [ + { + "type": "parse-error", + "text": ":", + "range": "[(0,5)..(0,6)]", + "tokenTypeName": "colon" + } + ], + "tokenTypeName": "colon", + "previousToken": { + "type": "parse-error", + "text": ":", + "range": "[(0,4)..(0,5)]", + "tokenTypeName": "colon" + }, + "message": "Expecting: one of these possible Token sequences:\n 1. [string-value]\n 2. [number-value]\n 3. [{]\n 4. [[]\n 5. [boolean-value]\n 6. [null-value]\nbut found: ':'" + }, + { + "type": "parse-error", + "range": "[(0,6)..(0,7)]", + "text": ":", + "merged": [ + { + "type": "parse-error", + "text": ":", + "range": "[(0,6)..(0,7)]", + "tokenTypeName": "colon" + } + ], + "tokenTypeName": "colon", + "previousToken": { + "type": "parse-error", + "text": ":", + "range": "[(0,5)..(0,6)]", + "tokenTypeName": "colon" + }, + "message": "Expecting: one of these possible Token sequences:\n 1. [string-value]\n 2. [number-value]\n 3. [{]\n 4. [[]\n 5. [boolean-value]\n 6. [null-value]\nbut found: ':'" + }, + { + "type": "parse-error", + "range": "[(0,7)..(0,8)]", + "text": ":", + "merged": [ + { + "type": "parse-error", + "text": ":", + "range": "[(0,7)..(0,8)]", + "tokenTypeName": "colon" + } + ], + "tokenTypeName": "colon", + "previousToken": { + "type": "parse-error", + "text": ":", + "range": "[(0,6)..(0,7)]", + "tokenTypeName": "colon" + }, + "message": "Expecting: one of these possible Token sequences:\n 1. [string-value]\n 2. [number-value]\n 3. [{]\n 4. [[]\n 5. [boolean-value]\n 6. [null-value]\nbut found: ':'" + } +] diff --git a/packages/binding-parser/test/unit/data/comma-only/ast.json b/packages/binding-parser/test/unit/data/comma-only/ast.json new file mode 100644 index 000000000..8058306e4 --- /dev/null +++ b/packages/binding-parser/test/unit/data/comma-only/ast.json @@ -0,0 +1,28 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,2)..(0,3)]" + }, + "range": "[(0,0)..(0,3)]", + "commas": [ + { + "type": "comma", + "text": ",", + "range": "[(0,1)..(0,2)]" + } + ], + "type": "structure-value" + } + ], + "spaces": [], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/comma-only/cst.json b/packages/binding-parser/test/unit/data/comma-only/cst.json new file mode 100644 index 000000000..76b83911d --- /dev/null +++ b/packages/binding-parser/test/unit/data/comma-only/cst.json @@ -0,0 +1,44 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "comma": [ + { + "image": ",", + "startColumn": 2, + "endColumn": 2, + "tokenTypeName": "comma" + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 3, + "endColumn": 3, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 3 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 3 + } +} diff --git a/packages/binding-parser/test/unit/data/comma-only/input.txt b/packages/binding-parser/test/unit/data/comma-only/input.txt new file mode 100644 index 000000000..4f7034e21 --- /dev/null +++ b/packages/binding-parser/test/unit/data/comma-only/input.txt @@ -0,0 +1 @@ +{,} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/comma-only/lexer-errors.json b/packages/binding-parser/test/unit/data/comma-only/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/comma-only/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/comma-only/parse-errors.json b/packages/binding-parser/test/unit/data/comma-only/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/comma-only/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/curly-only/ast.json b/packages/binding-parser/test/unit/data/curly-only/ast.json new file mode 100644 index 000000000..15b447804 --- /dev/null +++ b/packages/binding-parser/test/unit/data/curly-only/ast.json @@ -0,0 +1,22 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,1)..(0,2)]" + }, + "range": "[(0,0)..(0,2)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/curly-only/cst.json b/packages/binding-parser/test/unit/data/curly-only/cst.json new file mode 100644 index 000000000..b1b38614c --- /dev/null +++ b/packages/binding-parser/test/unit/data/curly-only/cst.json @@ -0,0 +1,36 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 2, + "endColumn": 2, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 2 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 2 + } +} diff --git a/packages/binding-parser/test/unit/data/curly-only/input.txt b/packages/binding-parser/test/unit/data/curly-only/input.txt new file mode 100644 index 000000000..9e26dfeeb --- /dev/null +++ b/packages/binding-parser/test/unit/data/curly-only/input.txt @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/curly-only/lexer-errors.json b/packages/binding-parser/test/unit/data/curly-only/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/curly-only/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/curly-only/parse-errors.json b/packages/binding-parser/test/unit/data/curly-only/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/curly-only/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/key-only/ast.json b/packages/binding-parser/test/unit/data/key-only/ast.json new file mode 100644 index 000000000..597bdac13 --- /dev/null +++ b/packages/binding-parser/test/unit/data/key-only/ast.json @@ -0,0 +1,41 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,1)..(0,4)]", + "originalText": "key" + }, + "colon": "undefined", + "value": "undefined", + "range": "[(0,1)..(0,4)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,5)..(0,6)]" + }, + "range": "[(0,0)..(0,6)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,4)..(0,5)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/key-only/cst.json b/packages/binding-parser/test/unit/data/key-only/cst.json new file mode 100644 index 000000000..ce93b2d03 --- /dev/null +++ b/packages/binding-parser/test/unit/data/key-only/cst.json @@ -0,0 +1,55 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 2, + "endColumn": 4, + "tokenTypeName": "key" + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 4 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 6, + "endColumn": 6, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 6 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 6 + } +} diff --git a/packages/binding-parser/test/unit/data/key-only/input.txt b/packages/binding-parser/test/unit/data/key-only/input.txt new file mode 100644 index 000000000..50828e562 --- /dev/null +++ b/packages/binding-parser/test/unit/data/key-only/input.txt @@ -0,0 +1 @@ +{key } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/key-only/lexer-errors.json b/packages/binding-parser/test/unit/data/key-only/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/key-only/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/key-only/parse-errors.json b/packages/binding-parser/test/unit/data/key-only/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/key-only/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/missing-comma/ast.json b/packages/binding-parser/test/unit/data/missing-comma/ast.json new file mode 100644 index 000000000..9a244ecb2 --- /dev/null +++ b/packages/binding-parser/test/unit/data/missing-comma/ast.json @@ -0,0 +1,79 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key01", + "range": "[(0,1)..(0,6)]", + "originalText": "key01" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,6)..(0,7)]" + }, + "value": { + "type": "string-value", + "text": "'value-01'", + "range": "[(0,8)..(0,18)]" + }, + "range": "[(0,1)..(0,18)]", + "type": "structure-element" + }, + { + "key": { + "type": "key", + "text": "key02", + "range": "[(0,19)..(0,24)]", + "originalText": "key02" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,24)..(0,25)]" + }, + "value": { + "type": "string-value", + "text": "'value-02'", + "range": "[(0,26)..(0,36)]" + }, + "range": "[(0,19)..(0,36)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,36)..(0,37)]" + }, + "range": "[(0,0)..(0,37)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,7)..(0,8)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,18)..(0,19)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,25)..(0,26)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/missing-comma/cst.json b/packages/binding-parser/test/unit/data/missing-comma/cst.json new file mode 100644 index 000000000..fe74fea38 --- /dev/null +++ b/packages/binding-parser/test/unit/data/missing-comma/cst.json @@ -0,0 +1,126 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key01", + "startColumn": 2, + "endColumn": 6, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 7, + "endColumn": 7, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'value-01'", + "startColumn": 9, + "endColumn": 18, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 9, + "endColumn": 18 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 18 + } + }, + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key02", + "startColumn": 20, + "endColumn": 24, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 25, + "endColumn": 25, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'value-02'", + "startColumn": 27, + "endColumn": 36, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 27, + "endColumn": 36 + } + } + ] + }, + "location": { + "startColumn": 20, + "endColumn": 36 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 37, + "endColumn": 37, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 37 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 37 + } +} diff --git a/packages/binding-parser/test/unit/data/missing-comma/input.txt b/packages/binding-parser/test/unit/data/missing-comma/input.txt new file mode 100644 index 000000000..7cb75ce4e --- /dev/null +++ b/packages/binding-parser/test/unit/data/missing-comma/input.txt @@ -0,0 +1 @@ +{key01: 'value-01' key02: 'value-02'} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/missing-comma/lexer-errors.json b/packages/binding-parser/test/unit/data/missing-comma/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/missing-comma/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/missing-comma/parse-errors.json b/packages/binding-parser/test/unit/data/missing-comma/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/missing-comma/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/missing-left-curly/ast.json b/packages/binding-parser/test/unit/data/missing-left-curly/ast.json new file mode 100644 index 000000000..751a91bbc --- /dev/null +++ b/packages/binding-parser/test/unit/data/missing-left-curly/ast.json @@ -0,0 +1,11 @@ +{ + "bindings": [], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,4)..(0,5)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/missing-left-curly/cst.json b/packages/binding-parser/test/unit/data/missing-left-curly/cst.json new file mode 100644 index 000000000..533fd870a --- /dev/null +++ b/packages/binding-parser/test/unit/data/missing-left-curly/cst.json @@ -0,0 +1,8 @@ +{ + "name": "template", + "children": {}, + "location": { + "startColumn": -1, + "endColumn": -1 + } +} diff --git a/packages/binding-parser/test/unit/data/missing-left-curly/input.txt b/packages/binding-parser/test/unit/data/missing-left-curly/input.txt new file mode 100644 index 000000000..b11d0fe36 --- /dev/null +++ b/packages/binding-parser/test/unit/data/missing-left-curly/input.txt @@ -0,0 +1 @@ +key: 'value'} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/missing-left-curly/lexer-errors.json b/packages/binding-parser/test/unit/data/missing-left-curly/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/missing-left-curly/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/missing-left-curly/parse-errors.json b/packages/binding-parser/test/unit/data/missing-left-curly/parse-errors.json new file mode 100644 index 000000000..f7ef2b120 --- /dev/null +++ b/packages/binding-parser/test/unit/data/missing-left-curly/parse-errors.json @@ -0,0 +1,35 @@ +[ + { + "type": "parse-error", + "range": "[(0,0)..(0,12)]", + "text": "key:'value'", + "merged": [ + { + "type": "parse-error", + "text": "key", + "range": "[(0,0)..(0,3)]", + "tokenTypeName": "key" + }, + { + "type": "parse-error", + "text": ":", + "range": "[(0,3)..(0,4)]", + "tokenTypeName": "colon" + }, + { + "type": "parse-error", + "text": "'value'", + "range": "[(0,5)..(0,12)]", + "tokenTypeName": "string-value" + } + ], + "tokenTypeName": "key|colon|string-value", + "previousToken": { + "type": "parse-error", + "text": "}", + "range": "[(0,12)..(0,13)]", + "tokenTypeName": "right-curly" + }, + "message": "Expecting token of type --> EOF <-- but found --> 'key' <--" + } +] diff --git a/packages/binding-parser/test/unit/data/missing-right-curly/ast.json b/packages/binding-parser/test/unit/data/missing-right-curly/ast.json new file mode 100644 index 000000000..ecb16826a --- /dev/null +++ b/packages/binding-parser/test/unit/data/missing-right-curly/ast.json @@ -0,0 +1,45 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,1)..(0,4)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,4)..(0,5)]" + }, + "value": { + "type": "string-value", + "text": "'value'", + "range": "[(0,6)..(0,13)]" + }, + "range": "[(0,1)..(0,13)]", + "type": "structure-element" + } + ], + "rightCurly": "undefined", + "range": "[(0,0)..(0,13)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,5)..(0,6)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/missing-right-curly/cst.json b/packages/binding-parser/test/unit/data/missing-right-curly/cst.json new file mode 100644 index 000000000..8c1dde4f5 --- /dev/null +++ b/packages/binding-parser/test/unit/data/missing-right-curly/cst.json @@ -0,0 +1,76 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 2, + "endColumn": 4, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 5, + "endColumn": 5, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'value'", + "startColumn": 7, + "endColumn": 13, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 7, + "endColumn": 13 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 13 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 13 + }, + "recoveredNode": true + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 13 + }, + "recoveredNode": true +} diff --git a/packages/binding-parser/test/unit/data/missing-right-curly/input.txt b/packages/binding-parser/test/unit/data/missing-right-curly/input.txt new file mode 100644 index 000000000..f58322641 --- /dev/null +++ b/packages/binding-parser/test/unit/data/missing-right-curly/input.txt @@ -0,0 +1 @@ +{key: 'value' \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/missing-right-curly/lexer-errors.json b/packages/binding-parser/test/unit/data/missing-right-curly/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/missing-right-curly/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/missing-right-curly/parse-errors.json b/packages/binding-parser/test/unit/data/missing-right-curly/parse-errors.json new file mode 100644 index 000000000..0628cd480 --- /dev/null +++ b/packages/binding-parser/test/unit/data/missing-right-curly/parse-errors.json @@ -0,0 +1,23 @@ +[ + { + "type": "parse-error", + "range": "[(0,0)..(0,0)]", + "text": "", + "merged": [ + { + "type": "parse-error", + "text": "", + "range": "[(0,0)..(0,0)]", + "tokenTypeName": "EOF" + } + ], + "tokenTypeName": "EOF", + "previousToken": { + "type": "parse-error", + "text": "'value'", + "range": "[(0,6)..(0,13)]", + "tokenTypeName": "string-value" + }, + "message": "Expecting --> } <-- but found --> '' <--" + } +] diff --git a/packages/binding-parser/test/unit/data/multiple-bindings-special-chars/ast.json b/packages/binding-parser/test/unit/data/multiple-bindings-special-chars/ast.json new file mode 100644 index 000000000..708355656 --- /dev/null +++ b/packages/binding-parser/test/unit/data/multiple-bindings-special-chars/ast.json @@ -0,0 +1,116 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,5)..(0,6)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "path", + "range": "[(0,6)..(0,10)]", + "originalText": "path" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,10)..(0,11)]" + }, + "value": { + "type": "string-value", + "text": "'###'", + "range": "[(0,12)..(0,17)]" + }, + "range": "[(0,6)..(0,17)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,17)..(0,18)]" + }, + "range": "[(0,5)..(0,18)]", + "commas": [], + "type": "structure-value" + }, + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(2,3)..(2,4)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "pat", + "range": "[(2,5)..(2,8)]", + "originalText": "pat" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(2,8)..(2,9)]" + }, + "value": { + "type": "string-value", + "text": "' '", + "range": "[(2,9)..(2,12)]" + }, + "range": "[(2,5)..(2,12)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(2,12)..(2,13)]" + }, + "range": "[(2,3)..(2,13)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,4)..(0,5)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,11)..(0,12)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,18)..(0,19)]" + }, + { + "type": "white-space", + "text": "\n\n", + "range": "[(0,21)..(1,1)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(2,2)..(2,3)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(2,13)..(2,14)]" + }, + { + "type": "white-space", + "text": "\n", + "range": "[(2,18)..(2,19)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/multiple-bindings-special-chars/cst.json b/packages/binding-parser/test/unit/data/multiple-bindings-special-chars/cst.json new file mode 100644 index 000000000..08cdbc442 --- /dev/null +++ b/packages/binding-parser/test/unit/data/multiple-bindings-special-chars/cst.json @@ -0,0 +1,153 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 6, + "endColumn": 6, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "path", + "startColumn": 7, + "endColumn": 10, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 11, + "endColumn": 11, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'###'", + "startColumn": 13, + "endColumn": 17, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 13, + "endColumn": 17 + } + } + ] + }, + "location": { + "startColumn": 7, + "endColumn": 17 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 18, + "endColumn": 18, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 6, + "endColumn": 18 + } + }, + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 4, + "endColumn": 4, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "pat", + "startColumn": 6, + "endColumn": 8, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 9, + "endColumn": 9, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "' '", + "startColumn": 10, + "endColumn": 12, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 10, + "endColumn": 12 + } + } + ] + }, + "location": { + "startColumn": 6, + "endColumn": 12 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 13, + "endColumn": 13, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 4, + "endColumn": 13 + } + } + ] + }, + "location": { + "startColumn": 6, + "endColumn": 13 + } +} diff --git a/packages/binding-parser/test/unit/data/multiple-bindings-special-chars/input.txt b/packages/binding-parser/test/unit/data/multiple-bindings-special-chars/input.txt new file mode 100644 index 000000000..558263ced --- /dev/null +++ b/packages/binding-parser/test/unit/data/multiple-bindings-special-chars/input.txt @@ -0,0 +1,3 @@ +???? {path: '###'} ## + +## {#pat:' '} >>>> diff --git a/packages/binding-parser/test/unit/data/multiple-bindings-special-chars/lexer-errors.json b/packages/binding-parser/test/unit/data/multiple-bindings-special-chars/lexer-errors.json new file mode 100644 index 000000000..c420875b9 --- /dev/null +++ b/packages/binding-parser/test/unit/data/multiple-bindings-special-chars/lexer-errors.json @@ -0,0 +1,27 @@ +[ + { + "type": "special-chars", + "text": "????", + "range": "[(0,0)..(0,4)]" + }, + { + "type": "special-chars", + "text": "##", + "range": "[(0,19)..(0,21)]" + }, + { + "type": "special-chars", + "text": "##", + "range": "[(2,0)..(2,2)]" + }, + { + "type": "special-chars", + "text": "#", + "range": "[(2,4)..(2,5)]" + }, + { + "type": "special-chars", + "text": ">>>>", + "range": "[(2,14)..(2,18)]" + } +] diff --git a/packages/binding-parser/test/unit/data/multiple-bindings-special-chars/parse-errors.json b/packages/binding-parser/test/unit/data/multiple-bindings-special-chars/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/multiple-bindings-special-chars/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/multiple-bindings/ast.json b/packages/binding-parser/test/unit/data/multiple-bindings/ast.json new file mode 100644 index 000000000..e3d94110e --- /dev/null +++ b/packages/binding-parser/test/unit/data/multiple-bindings/ast.json @@ -0,0 +1,180 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "keyFirst01", + "range": "[(0,1)..(0,11)]", + "originalText": "keyFirst01" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,11)..(0,12)]" + }, + "value": { + "type": "string-value", + "text": "'first'", + "range": "[(0,13)..(0,20)]" + }, + "range": "[(0,1)..(0,20)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,20)..(0,21)]" + }, + "range": "[(0,0)..(0,21)]", + "commas": [], + "type": "structure-value" + }, + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,22)..(0,23)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "keySecond01", + "range": "[(0,23)..(0,34)]", + "originalText": "keySecond01" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,34)..(0,35)]" + }, + "value": { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,36)..(0,37)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,37)..(0,40)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,40)..(0,41)]" + }, + "value": { + "type": "string-value", + "text": "'second-01'", + "range": "[(0,42)..(0,53)]" + }, + "range": "[(0,37)..(0,53)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,53)..(0,54)]" + }, + "range": "[(0,36)..(0,54)]", + "commas": [], + "type": "structure-value" + }, + "range": "[(0,23)..(0,54)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,54)..(0,55)]" + }, + "range": "[(0,22)..(0,55)]", + "commas": [], + "type": "structure-value" + }, + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,56)..(0,57)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "keyThird", + "range": "[(0,57)..(0,65)]", + "originalText": "keyThird" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,65)..(0,66)]" + }, + "value": { + "type": "string-value", + "text": "'third'", + "range": "[(0,67)..(0,74)]" + }, + "range": "[(0,57)..(0,74)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,74)..(0,75)]" + }, + "range": "[(0,56)..(0,75)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,12)..(0,13)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,21)..(0,22)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,35)..(0,36)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,41)..(0,42)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,55)..(0,56)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,66)..(0,67)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/multiple-bindings/cst.json b/packages/binding-parser/test/unit/data/multiple-bindings/cst.json new file mode 100644 index 000000000..26a1c8776 --- /dev/null +++ b/packages/binding-parser/test/unit/data/multiple-bindings/cst.json @@ -0,0 +1,289 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "keyFirst01", + "startColumn": 2, + "endColumn": 11, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 12, + "endColumn": 12, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'first'", + "startColumn": 14, + "endColumn": 20, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 14, + "endColumn": 20 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 20 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 21, + "endColumn": 21, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 21 + } + }, + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 23, + "endColumn": 23, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "keySecond01", + "startColumn": 24, + "endColumn": 34, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 35, + "endColumn": 35, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 37, + "endColumn": 37, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 38, + "endColumn": 40, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 41, + "endColumn": 41, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'second-01'", + "startColumn": 43, + "endColumn": 53, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 43, + "endColumn": 53 + } + } + ] + }, + "location": { + "startColumn": 38, + "endColumn": 53 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 54, + "endColumn": 54, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 37, + "endColumn": 54 + } + } + ] + }, + "location": { + "startColumn": 37, + "endColumn": 54 + } + } + ] + }, + "location": { + "startColumn": 24, + "endColumn": 54 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 55, + "endColumn": 55, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 23, + "endColumn": 55 + } + }, + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 57, + "endColumn": 57, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "keyThird", + "startColumn": 58, + "endColumn": 65, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 66, + "endColumn": 66, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'third'", + "startColumn": 68, + "endColumn": 74, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 68, + "endColumn": 74 + } + } + ] + }, + "location": { + "startColumn": 58, + "endColumn": 74 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 75, + "endColumn": 75, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 57, + "endColumn": 75 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 75 + } +} diff --git a/packages/binding-parser/test/unit/data/multiple-bindings/input.txt b/packages/binding-parser/test/unit/data/multiple-bindings/input.txt new file mode 100644 index 000000000..41c467145 --- /dev/null +++ b/packages/binding-parser/test/unit/data/multiple-bindings/input.txt @@ -0,0 +1 @@ +{keyFirst01: 'first'} {keySecond01: {key: 'second-01'}} {keyThird: 'third'} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/multiple-bindings/lexer-errors.json b/packages/binding-parser/test/unit/data/multiple-bindings/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/multiple-bindings/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/multiple-bindings/parse-errors.json b/packages/binding-parser/test/unit/data/multiple-bindings/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/multiple-bindings/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/multiple-lines-with-position/ast.json b/packages/binding-parser/test/unit/data/multiple-lines-with-position/ast.json new file mode 100644 index 000000000..e74604d01 --- /dev/null +++ b/packages/binding-parser/test/unit/data/multiple-lines-with-position/ast.json @@ -0,0 +1,125 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(5,15)..(5,16)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key01", + "range": "[(5,16)..(5,21)]", + "originalText": "key01" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(5,21)..(5,22)]" + }, + "value": { + "type": "string-value", + "text": "'value-01'", + "range": "[(5,23)..(5,33)]" + }, + "range": "[(5,16)..(5,33)]", + "type": "structure-element" + }, + { + "key": { + "type": "key", + "text": "key02", + "range": "[(7,1)..(7,6)]", + "originalText": "key02" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(7,6)..(7,7)]" + }, + "value": { + "type": "string-value", + "text": "'value-01'", + "range": "[(7,8)..(7,18)]" + }, + "range": "[(7,1)..(7,18)]", + "type": "structure-element" + }, + { + "key": { + "type": "key", + "text": "key03", + "range": "[(9,4)..(9,9)]", + "originalText": "key03" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(9,9)..(9,10)]" + }, + "value": { + "type": "string-value", + "text": "'value-03'", + "range": "[(9,11)..(9,21)]" + }, + "range": "[(9,4)..(9,21)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(10,0)..(10,1)]" + }, + "range": "[(5,15)..(10,1)]", + "commas": [ + { + "type": "comma", + "text": ",", + "range": "[(5,33)..(5,34)]" + }, + { + "type": "comma", + "text": ",", + "range": "[(7,18)..(7,19)]" + } + ], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(5,22)..(5,23)]" + }, + { + "type": "white-space", + "text": "\n\n\t", + "range": "[(5,34)..(7,1)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(7,7)..(7,8)]" + }, + { + "type": "white-space", + "text": "\n\n ", + "range": "[(7,19)..(9,4)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(9,10)..(9,11)]" + }, + { + "type": "white-space", + "text": "\n", + "range": "[(9,21)..(9,22)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/multiple-lines-with-position/cst.json b/packages/binding-parser/test/unit/data/multiple-lines-with-position/cst.json new file mode 100644 index 000000000..2371fafe6 --- /dev/null +++ b/packages/binding-parser/test/unit/data/multiple-lines-with-position/cst.json @@ -0,0 +1,184 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key01", + "startColumn": 2, + "endColumn": 6, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 7, + "endColumn": 7, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'value-01'", + "startColumn": 9, + "endColumn": 18, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 9, + "endColumn": 18 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 18 + } + }, + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key02", + "startColumn": 2, + "endColumn": 6, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 7, + "endColumn": 7, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'value-01'", + "startColumn": 9, + "endColumn": 18, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 9, + "endColumn": 18 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 18 + } + }, + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key03", + "startColumn": 5, + "endColumn": 9, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 10, + "endColumn": 10, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'value-03'", + "startColumn": 12, + "endColumn": 21, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 12, + "endColumn": 21 + } + } + ] + }, + "location": { + "startColumn": 5, + "endColumn": 21 + } + } + ], + "comma": [ + { + "image": ",", + "startColumn": 19, + "endColumn": 19, + "tokenTypeName": "comma" + }, + { + "image": ",", + "startColumn": 19, + "endColumn": 19, + "tokenTypeName": "comma" + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 1 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 1 + } +} diff --git a/packages/binding-parser/test/unit/data/multiple-lines-with-position/input.txt b/packages/binding-parser/test/unit/data/multiple-lines-with-position/input.txt new file mode 100644 index 000000000..11505829e --- /dev/null +++ b/packages/binding-parser/test/unit/data/multiple-lines-with-position/input.txt @@ -0,0 +1,6 @@ +{key01: 'value-01', + + key02: 'value-01', + + key03: 'value-03' +} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/multiple-lines-with-position/lexer-errors.json b/packages/binding-parser/test/unit/data/multiple-lines-with-position/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/multiple-lines-with-position/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/multiple-lines-with-position/parse-errors.json b/packages/binding-parser/test/unit/data/multiple-lines-with-position/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/multiple-lines-with-position/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/multiple-lines-with-position/position.json b/packages/binding-parser/test/unit/data/multiple-lines-with-position/position.json new file mode 100644 index 000000000..3606ab8d1 --- /dev/null +++ b/packages/binding-parser/test/unit/data/multiple-lines-with-position/position.json @@ -0,0 +1,4 @@ +{ + "line": 5, + "character": 15 +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/double-quotes/ast.json b/packages/binding-parser/test/unit/data/quotes/key-colon-value/double-quotes/ast.json new file mode 100644 index 000000000..33388528f --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/double-quotes/ast.json @@ -0,0 +1,49 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "abc", + "range": "[(0,1)..(0,6)]", + "originalText": "\"abc\"" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,6)..(0,7)]" + }, + "value": { + "type": "string-value", + "text": "\"xyz\"", + "range": "[(0,8)..(0,13)]" + }, + "range": "[(0,1)..(0,13)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,13)..(0,14)]" + }, + "range": "[(0,0)..(0,14)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,7)..(0,8)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/double-quotes/cst.json b/packages/binding-parser/test/unit/data/quotes/key-colon-value/double-quotes/cst.json new file mode 100644 index 000000000..a9af79b69 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/double-quotes/cst.json @@ -0,0 +1,82 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "string-value": [ + { + "image": "\"abc\"", + "startColumn": 2, + "endColumn": 6, + "tokenTypeName": "string-value" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 7, + "endColumn": 7, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "\"xyz\"", + "startColumn": 9, + "endColumn": 13, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 9, + "endColumn": 13 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 13 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 14, + "endColumn": 14, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 14 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 14 + } +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/double-quotes/input.txt b/packages/binding-parser/test/unit/data/quotes/key-colon-value/double-quotes/input.txt new file mode 100644 index 000000000..bd943ce61 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/double-quotes/input.txt @@ -0,0 +1 @@ +{"abc": "xyz"} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/double-quotes/lexer-errors.json b/packages/binding-parser/test/unit/data/quotes/key-colon-value/double-quotes/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/double-quotes/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/double-quotes/parse-errors.json b/packages/binding-parser/test/unit/data/quotes/key-colon-value/double-quotes/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/double-quotes/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/double-quotes/ast.json b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/double-quotes/ast.json new file mode 100644 index 000000000..259540b31 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/double-quotes/ast.json @@ -0,0 +1,49 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "KeyHer", + "range": "[(0,1)..(0,19)]", + "originalText": ""KeyHer"" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,19)..(0,20)]" + }, + "value": { + "type": "string-value", + "text": ""ValueHer"", + "range": "[(0,21)..(0,41)]" + }, + "range": "[(0,1)..(0,41)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,41)..(0,42)]" + }, + "range": "[(0,0)..(0,42)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,20)..(0,21)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/double-quotes/cst.json b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/double-quotes/cst.json new file mode 100644 index 000000000..d2d633e6a --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/double-quotes/cst.json @@ -0,0 +1,82 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "string-value": [ + { + "image": ""KeyHer"", + "startColumn": 2, + "endColumn": 19, + "tokenTypeName": "string-value" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 20, + "endColumn": 20, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": ""ValueHer"", + "startColumn": 22, + "endColumn": 41, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 22, + "endColumn": 41 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 41 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 42, + "endColumn": 42, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 42 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 42 + } +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/double-quotes/input.txt b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/double-quotes/input.txt new file mode 100644 index 000000000..9380a12f0 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/double-quotes/input.txt @@ -0,0 +1 @@ +{"KeyHer": "ValueHer"} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/double-quotes/lexer-errors.json b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/double-quotes/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/double-quotes/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/double-quotes/parse-errors.json b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/double-quotes/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/double-quotes/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/single-quotes/ast.json b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/single-quotes/ast.json new file mode 100644 index 000000000..d2f048925 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/single-quotes/ast.json @@ -0,0 +1,49 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "KeyHere", + "range": "[(0,1)..(0,20)]", + "originalText": "'KeyHere'" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,20)..(0,21)]" + }, + "value": { + "type": "string-value", + "text": "'ValueHere'", + "range": "[(0,22)..(0,43)]" + }, + "range": "[(0,1)..(0,43)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,43)..(0,44)]" + }, + "range": "[(0,0)..(0,44)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,21)..(0,22)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/single-quotes/cst.json b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/single-quotes/cst.json new file mode 100644 index 000000000..98a0cb484 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/single-quotes/cst.json @@ -0,0 +1,82 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "string-value": [ + { + "image": "'KeyHere'", + "startColumn": 2, + "endColumn": 20, + "tokenTypeName": "string-value" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 21, + "endColumn": 21, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'ValueHere'", + "startColumn": 23, + "endColumn": 43, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 23, + "endColumn": 43 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 43 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 44, + "endColumn": 44, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 44 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 44 + } +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/single-quotes/input.txt b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/single-quotes/input.txt new file mode 100644 index 000000000..cffb1c487 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/single-quotes/input.txt @@ -0,0 +1 @@ +{'KeyHere': 'ValueHere'} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/single-quotes/lexer-errors.json b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/single-quotes/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/single-quotes/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/single-quotes/parse-errors.json b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/single-quotes/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/html-equivalent/single-quotes/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/single-quotes/ast.json b/packages/binding-parser/test/unit/data/quotes/key-colon-value/single-quotes/ast.json new file mode 100644 index 000000000..8d04e0eaf --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/single-quotes/ast.json @@ -0,0 +1,49 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "abc", + "range": "[(0,1)..(0,6)]", + "originalText": "'abc'" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,6)..(0,7)]" + }, + "value": { + "type": "string-value", + "text": "'xyz'", + "range": "[(0,8)..(0,13)]" + }, + "range": "[(0,1)..(0,13)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,13)..(0,14)]" + }, + "range": "[(0,0)..(0,14)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,7)..(0,8)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/single-quotes/cst.json b/packages/binding-parser/test/unit/data/quotes/key-colon-value/single-quotes/cst.json new file mode 100644 index 000000000..0fc867693 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/single-quotes/cst.json @@ -0,0 +1,82 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "string-value": [ + { + "image": "'abc'", + "startColumn": 2, + "endColumn": 6, + "tokenTypeName": "string-value" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 7, + "endColumn": 7, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'xyz'", + "startColumn": 9, + "endColumn": 13, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 9, + "endColumn": 13 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 13 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 14, + "endColumn": 14, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 14 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 14 + } +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/single-quotes/input.txt b/packages/binding-parser/test/unit/data/quotes/key-colon-value/single-quotes/input.txt new file mode 100644 index 000000000..530e52f90 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/single-quotes/input.txt @@ -0,0 +1 @@ +{'abc': 'xyz'} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/single-quotes/lexer-errors.json b/packages/binding-parser/test/unit/data/quotes/key-colon-value/single-quotes/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/single-quotes/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon-value/single-quotes/parse-errors.json b/packages/binding-parser/test/unit/data/quotes/key-colon-value/single-quotes/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon-value/single-quotes/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/double-quotes/ast.json b/packages/binding-parser/test/unit/data/quotes/key-colon/double-quotes/ast.json new file mode 100644 index 000000000..02e40101e --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/double-quotes/ast.json @@ -0,0 +1,39 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "abc", + "range": "[(0,1)..(0,6)]", + "originalText": "\"abc\"" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,6)..(0,7)]" + }, + "value": "undefined", + "range": "[(0,1)..(0,7)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,7)..(0,8)]" + }, + "range": "[(0,0)..(0,8)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/double-quotes/cst.json b/packages/binding-parser/test/unit/data/quotes/key-colon/double-quotes/cst.json new file mode 100644 index 000000000..52dc62d18 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/double-quotes/cst.json @@ -0,0 +1,75 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "string-value": [ + { + "image": "\"abc\"", + "startColumn": 2, + "endColumn": 6, + "tokenTypeName": "string-value" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 7, + "endColumn": 7, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": {}, + "location": { + "startColumn": -1, + "endColumn": -1 + }, + "recoveredNode": true + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 7 + }, + "recoveredNode": true + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 8, + "endColumn": 8, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 8 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 8 + } +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/double-quotes/input.txt b/packages/binding-parser/test/unit/data/quotes/key-colon/double-quotes/input.txt new file mode 100644 index 000000000..d9b73a72b --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/double-quotes/input.txt @@ -0,0 +1 @@ +{"abc":} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/double-quotes/lexer-errors.json b/packages/binding-parser/test/unit/data/quotes/key-colon/double-quotes/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/double-quotes/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/double-quotes/parse-errors.json b/packages/binding-parser/test/unit/data/quotes/key-colon/double-quotes/parse-errors.json new file mode 100644 index 000000000..44bbd9b60 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/double-quotes/parse-errors.json @@ -0,0 +1,23 @@ +[ + { + "type": "parse-error", + "range": "[(0,7)..(0,8)]", + "text": "}", + "merged": [ + { + "type": "parse-error", + "text": "}", + "range": "[(0,7)..(0,8)]", + "tokenTypeName": "right-curly" + } + ], + "tokenTypeName": "right-curly", + "previousToken": { + "type": "parse-error", + "text": ":", + "range": "[(0,6)..(0,7)]", + "tokenTypeName": "colon" + }, + "message": "Expecting: one of these possible Token sequences:\n 1. [string-value]\n 2. [number-value]\n 3. [{]\n 4. [[]\n 5. [boolean-value]\n 6. [null-value]\nbut found: '}'" + } +] diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/double-quotes/ast.json b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/double-quotes/ast.json new file mode 100644 index 000000000..685fe50f1 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/double-quotes/ast.json @@ -0,0 +1,39 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "KeyHer", + "range": "[(0,1)..(0,19)]", + "originalText": ""KeyHer"" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,19)..(0,20)]" + }, + "value": "undefined", + "range": "[(0,1)..(0,20)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,20)..(0,21)]" + }, + "range": "[(0,0)..(0,21)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/double-quotes/cst.json b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/double-quotes/cst.json new file mode 100644 index 000000000..6cc09a98a --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/double-quotes/cst.json @@ -0,0 +1,75 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "string-value": [ + { + "image": ""KeyHer"", + "startColumn": 2, + "endColumn": 19, + "tokenTypeName": "string-value" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 20, + "endColumn": 20, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": {}, + "location": { + "startColumn": -1, + "endColumn": -1 + }, + "recoveredNode": true + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 20 + }, + "recoveredNode": true + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 21, + "endColumn": 21, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 21 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 21 + } +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/double-quotes/input.txt b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/double-quotes/input.txt new file mode 100644 index 000000000..5d206dd6d --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/double-quotes/input.txt @@ -0,0 +1 @@ +{"KeyHer":} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/double-quotes/lexer-errors.json b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/double-quotes/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/double-quotes/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/double-quotes/parse-errors.json b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/double-quotes/parse-errors.json new file mode 100644 index 000000000..5ed5b0ca8 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/double-quotes/parse-errors.json @@ -0,0 +1,23 @@ +[ + { + "type": "parse-error", + "range": "[(0,20)..(0,21)]", + "text": "}", + "merged": [ + { + "type": "parse-error", + "text": "}", + "range": "[(0,20)..(0,21)]", + "tokenTypeName": "right-curly" + } + ], + "tokenTypeName": "right-curly", + "previousToken": { + "type": "parse-error", + "text": ":", + "range": "[(0,19)..(0,20)]", + "tokenTypeName": "colon" + }, + "message": "Expecting: one of these possible Token sequences:\n 1. [string-value]\n 2. [number-value]\n 3. [{]\n 4. [[]\n 5. [boolean-value]\n 6. [null-value]\nbut found: '}'" + } +] diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/single-quotes/ast.json b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/single-quotes/ast.json new file mode 100644 index 000000000..838dba7d2 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/single-quotes/ast.json @@ -0,0 +1,39 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "KeyHere", + "range": "[(0,1)..(0,20)]", + "originalText": "'KeyHere'" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,20)..(0,21)]" + }, + "value": "undefined", + "range": "[(0,1)..(0,21)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,21)..(0,22)]" + }, + "range": "[(0,0)..(0,22)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/single-quotes/cst.json b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/single-quotes/cst.json new file mode 100644 index 000000000..86107f4bf --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/single-quotes/cst.json @@ -0,0 +1,75 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "string-value": [ + { + "image": "'KeyHere'", + "startColumn": 2, + "endColumn": 20, + "tokenTypeName": "string-value" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 21, + "endColumn": 21, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": {}, + "location": { + "startColumn": -1, + "endColumn": -1 + }, + "recoveredNode": true + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 21 + }, + "recoveredNode": true + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 22, + "endColumn": 22, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 22 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 22 + } +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/single-quotes/input.txt b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/single-quotes/input.txt new file mode 100644 index 000000000..72a6283f4 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/single-quotes/input.txt @@ -0,0 +1 @@ +{'KeyHere':} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/single-quotes/lexer-errors.json b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/single-quotes/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/single-quotes/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/single-quotes/parse-errors.json b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/single-quotes/parse-errors.json new file mode 100644 index 000000000..7462bbbb8 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/html-equivalent/single-quotes/parse-errors.json @@ -0,0 +1,23 @@ +[ + { + "type": "parse-error", + "range": "[(0,21)..(0,22)]", + "text": "}", + "merged": [ + { + "type": "parse-error", + "text": "}", + "range": "[(0,21)..(0,22)]", + "tokenTypeName": "right-curly" + } + ], + "tokenTypeName": "right-curly", + "previousToken": { + "type": "parse-error", + "text": ":", + "range": "[(0,20)..(0,21)]", + "tokenTypeName": "colon" + }, + "message": "Expecting: one of these possible Token sequences:\n 1. [string-value]\n 2. [number-value]\n 3. [{]\n 4. [[]\n 5. [boolean-value]\n 6. [null-value]\nbut found: '}'" + } +] diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/single-quotes/ast.json b/packages/binding-parser/test/unit/data/quotes/key-colon/single-quotes/ast.json new file mode 100644 index 000000000..efabc33ae --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/single-quotes/ast.json @@ -0,0 +1,39 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "abc", + "range": "[(0,1)..(0,6)]", + "originalText": "'abc'" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,6)..(0,7)]" + }, + "value": "undefined", + "range": "[(0,1)..(0,7)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,7)..(0,8)]" + }, + "range": "[(0,0)..(0,8)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/single-quotes/cst.json b/packages/binding-parser/test/unit/data/quotes/key-colon/single-quotes/cst.json new file mode 100644 index 000000000..db711541a --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/single-quotes/cst.json @@ -0,0 +1,75 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "string-value": [ + { + "image": "'abc'", + "startColumn": 2, + "endColumn": 6, + "tokenTypeName": "string-value" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 7, + "endColumn": 7, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": {}, + "location": { + "startColumn": -1, + "endColumn": -1 + }, + "recoveredNode": true + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 7 + }, + "recoveredNode": true + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 8, + "endColumn": 8, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 8 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 8 + } +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/single-quotes/input.txt b/packages/binding-parser/test/unit/data/quotes/key-colon/single-quotes/input.txt new file mode 100644 index 000000000..2676d9f2a --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/single-quotes/input.txt @@ -0,0 +1 @@ +{'abc':} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/single-quotes/lexer-errors.json b/packages/binding-parser/test/unit/data/quotes/key-colon/single-quotes/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/single-quotes/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-colon/single-quotes/parse-errors.json b/packages/binding-parser/test/unit/data/quotes/key-colon/single-quotes/parse-errors.json new file mode 100644 index 000000000..44bbd9b60 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-colon/single-quotes/parse-errors.json @@ -0,0 +1,23 @@ +[ + { + "type": "parse-error", + "range": "[(0,7)..(0,8)]", + "text": "}", + "merged": [ + { + "type": "parse-error", + "text": "}", + "range": "[(0,7)..(0,8)]", + "tokenTypeName": "right-curly" + } + ], + "tokenTypeName": "right-curly", + "previousToken": { + "type": "parse-error", + "text": ":", + "range": "[(0,6)..(0,7)]", + "tokenTypeName": "colon" + }, + "message": "Expecting: one of these possible Token sequences:\n 1. [string-value]\n 2. [number-value]\n 3. [{]\n 4. [[]\n 5. [boolean-value]\n 6. [null-value]\nbut found: '}'" + } +] diff --git a/packages/binding-parser/test/unit/data/quotes/key-only/ast.json b/packages/binding-parser/test/unit/data/quotes/key-only/ast.json new file mode 100644 index 000000000..f1b119ff4 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-only/ast.json @@ -0,0 +1,35 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "valueOnly", + "range": "[(0,1)..(0,12)]", + "originalText": "'valueOnly'" + }, + "colon": "undefined", + "value": "undefined", + "range": "[(0,1)..(0,12)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,12)..(0,13)]" + }, + "range": "[(0,0)..(0,13)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-only/cst.json b/packages/binding-parser/test/unit/data/quotes/key-only/cst.json new file mode 100644 index 000000000..b78ad850d --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-only/cst.json @@ -0,0 +1,55 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "string-value": [ + { + "image": "'valueOnly'", + "startColumn": 2, + "endColumn": 12, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 12 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 13, + "endColumn": 13, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 13 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 13 + } +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-only/input.txt b/packages/binding-parser/test/unit/data/quotes/key-only/input.txt new file mode 100644 index 000000000..08a73e2aa --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-only/input.txt @@ -0,0 +1 @@ +{'valueOnly'} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/quotes/key-only/lexer-errors.json b/packages/binding-parser/test/unit/data/quotes/key-only/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-only/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-only/parse-errors.json b/packages/binding-parser/test/unit/data/quotes/key-only/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-only/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/double-quotes/ast.json b/packages/binding-parser/test/unit/data/quotes/key-value/double-quotes/ast.json new file mode 100644 index 000000000..99d78bff0 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/double-quotes/ast.json @@ -0,0 +1,45 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "abc", + "range": "[(0,1)..(0,6)]", + "originalText": "\"abc\"" + }, + "colon": "undefined", + "value": { + "type": "string-value", + "text": "\"xyz\"", + "range": "[(0,7)..(0,12)]" + }, + "range": "[(0,1)..(0,12)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,12)..(0,13)]" + }, + "range": "[(0,0)..(0,13)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,6)..(0,7)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/double-quotes/cst.json b/packages/binding-parser/test/unit/data/quotes/key-value/double-quotes/cst.json new file mode 100644 index 000000000..113858982 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/double-quotes/cst.json @@ -0,0 +1,74 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "string-value": [ + { + "image": "\"abc\"", + "startColumn": 2, + "endColumn": 6, + "tokenTypeName": "string-value" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "\"xyz\"", + "startColumn": 8, + "endColumn": 12, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 12 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 12 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 13, + "endColumn": 13, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 13 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 13 + } +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/double-quotes/input.txt b/packages/binding-parser/test/unit/data/quotes/key-value/double-quotes/input.txt new file mode 100644 index 000000000..f14f5fbf5 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/double-quotes/input.txt @@ -0,0 +1 @@ +{"abc" "xyz"} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/double-quotes/lexer-errors.json b/packages/binding-parser/test/unit/data/quotes/key-value/double-quotes/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/double-quotes/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/double-quotes/parse-errors.json b/packages/binding-parser/test/unit/data/quotes/key-value/double-quotes/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/double-quotes/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/double-quotes/ast.json b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/double-quotes/ast.json new file mode 100644 index 000000000..916837cf1 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/double-quotes/ast.json @@ -0,0 +1,45 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "KeyHer", + "range": "[(0,1)..(0,19)]", + "originalText": ""KeyHer"" + }, + "colon": "undefined", + "value": { + "type": "string-value", + "text": ""ValueHer"", + "range": "[(0,20)..(0,40)]" + }, + "range": "[(0,1)..(0,40)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,40)..(0,41)]" + }, + "range": "[(0,0)..(0,41)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,19)..(0,20)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/double-quotes/cst.json b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/double-quotes/cst.json new file mode 100644 index 000000000..e36abb45b --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/double-quotes/cst.json @@ -0,0 +1,74 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "string-value": [ + { + "image": ""KeyHer"", + "startColumn": 2, + "endColumn": 19, + "tokenTypeName": "string-value" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": ""ValueHer"", + "startColumn": 21, + "endColumn": 40, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 21, + "endColumn": 40 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 40 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 41, + "endColumn": 41, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 41 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 41 + } +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/double-quotes/input.txt b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/double-quotes/input.txt new file mode 100644 index 000000000..e55520ecd --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/double-quotes/input.txt @@ -0,0 +1 @@ +{"KeyHer" "ValueHer"} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/double-quotes/lexer-errors.json b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/double-quotes/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/double-quotes/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/double-quotes/parse-errors.json b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/double-quotes/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/double-quotes/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/single-quotes/ast.json b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/single-quotes/ast.json new file mode 100644 index 000000000..c617e402b --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/single-quotes/ast.json @@ -0,0 +1,45 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "KeyHere", + "range": "[(0,1)..(0,20)]", + "originalText": "'KeyHere'" + }, + "colon": "undefined", + "value": { + "type": "string-value", + "text": "'ValueHere'", + "range": "[(0,21)..(0,42)]" + }, + "range": "[(0,1)..(0,42)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,42)..(0,43)]" + }, + "range": "[(0,0)..(0,43)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,20)..(0,21)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/single-quotes/cst.json b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/single-quotes/cst.json new file mode 100644 index 000000000..59e5a7368 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/single-quotes/cst.json @@ -0,0 +1,74 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "string-value": [ + { + "image": "'KeyHere'", + "startColumn": 2, + "endColumn": 20, + "tokenTypeName": "string-value" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'ValueHere'", + "startColumn": 22, + "endColumn": 42, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 22, + "endColumn": 42 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 42 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 43, + "endColumn": 43, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 43 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 43 + } +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/single-quotes/input.txt b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/single-quotes/input.txt new file mode 100644 index 000000000..fc89a0da7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/single-quotes/input.txt @@ -0,0 +1 @@ +{'KeyHere' 'ValueHere'} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/single-quotes/lexer-errors.json b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/single-quotes/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/single-quotes/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/single-quotes/parse-errors.json b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/single-quotes/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/html-equivalent/single-quotes/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/single-quotes/ast.json b/packages/binding-parser/test/unit/data/quotes/key-value/single-quotes/ast.json new file mode 100644 index 000000000..4c36db550 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/single-quotes/ast.json @@ -0,0 +1,45 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "abc", + "range": "[(0,1)..(0,6)]", + "originalText": "'abc'" + }, + "colon": "undefined", + "value": { + "type": "string-value", + "text": "'xyz'", + "range": "[(0,7)..(0,12)]" + }, + "range": "[(0,1)..(0,12)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,12)..(0,13)]" + }, + "range": "[(0,0)..(0,13)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,6)..(0,7)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/single-quotes/cst.json b/packages/binding-parser/test/unit/data/quotes/key-value/single-quotes/cst.json new file mode 100644 index 000000000..984ae7c34 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/single-quotes/cst.json @@ -0,0 +1,74 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "string-value": [ + { + "image": "'abc'", + "startColumn": 2, + "endColumn": 6, + "tokenTypeName": "string-value" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'xyz'", + "startColumn": 8, + "endColumn": 12, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 12 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 12 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 13, + "endColumn": 13, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 13 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 13 + } +} diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/single-quotes/input.txt b/packages/binding-parser/test/unit/data/quotes/key-value/single-quotes/input.txt new file mode 100644 index 000000000..cd72cfb9e --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/single-quotes/input.txt @@ -0,0 +1 @@ +{'abc' 'xyz'} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/single-quotes/lexer-errors.json b/packages/binding-parser/test/unit/data/quotes/key-value/single-quotes/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/single-quotes/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/quotes/key-value/single-quotes/parse-errors.json b/packages/binding-parser/test/unit/data/quotes/key-value/single-quotes/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/quotes/key-value/single-quotes/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/too-many-commas/ast.json b/packages/binding-parser/test/unit/data/too-many-commas/ast.json new file mode 100644 index 000000000..e3c3475ed --- /dev/null +++ b/packages/binding-parser/test/unit/data/too-many-commas/ast.json @@ -0,0 +1,95 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key01", + "range": "[(0,1)..(0,6)]", + "originalText": "key01" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,6)..(0,7)]" + }, + "value": { + "type": "string-value", + "text": "'value-01'", + "range": "[(0,8)..(0,18)]" + }, + "range": "[(0,1)..(0,18)]", + "type": "structure-element" + }, + { + "key": { + "type": "key", + "text": "key02", + "range": "[(0,22)..(0,27)]", + "originalText": "key02" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,27)..(0,28)]" + }, + "value": { + "type": "string-value", + "text": "'value-02'", + "range": "[(0,29)..(0,39)]" + }, + "range": "[(0,22)..(0,39)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,39)..(0,40)]" + }, + "range": "[(0,0)..(0,40)]", + "commas": [ + { + "type": "comma", + "text": ",", + "range": "[(0,18)..(0,19)]" + }, + { + "type": "comma", + "text": ",", + "range": "[(0,19)..(0,20)]" + }, + { + "type": "comma", + "text": ",", + "range": "[(0,20)..(0,21)]" + } + ], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,7)..(0,8)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,21)..(0,22)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,28)..(0,29)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/too-many-commas/cst.json b/packages/binding-parser/test/unit/data/too-many-commas/cst.json new file mode 100644 index 000000000..ee196f8a1 --- /dev/null +++ b/packages/binding-parser/test/unit/data/too-many-commas/cst.json @@ -0,0 +1,146 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key01", + "startColumn": 2, + "endColumn": 6, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 7, + "endColumn": 7, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'value-01'", + "startColumn": 9, + "endColumn": 18, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 9, + "endColumn": 18 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 18 + } + }, + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key02", + "startColumn": 23, + "endColumn": 27, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 28, + "endColumn": 28, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'value-02'", + "startColumn": 30, + "endColumn": 39, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 30, + "endColumn": 39 + } + } + ] + }, + "location": { + "startColumn": 23, + "endColumn": 39 + } + } + ], + "comma": [ + { + "image": ",", + "startColumn": 19, + "endColumn": 19, + "tokenTypeName": "comma" + }, + { + "image": ",", + "startColumn": 20, + "endColumn": 20, + "tokenTypeName": "comma" + }, + { + "image": ",", + "startColumn": 21, + "endColumn": 21, + "tokenTypeName": "comma" + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 40, + "endColumn": 40, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 40 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 40 + } +} diff --git a/packages/binding-parser/test/unit/data/too-many-commas/input.txt b/packages/binding-parser/test/unit/data/too-many-commas/input.txt new file mode 100644 index 000000000..1477801d2 --- /dev/null +++ b/packages/binding-parser/test/unit/data/too-many-commas/input.txt @@ -0,0 +1 @@ +{key01: 'value-01',,, key02: 'value-02'} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/too-many-commas/lexer-errors.json b/packages/binding-parser/test/unit/data/too-many-commas/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/too-many-commas/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/too-many-commas/parse-errors.json b/packages/binding-parser/test/unit/data/too-many-commas/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/too-many-commas/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/too-many-spaces/ast.json b/packages/binding-parser/test/unit/data/too-many-spaces/ast.json new file mode 100644 index 000000000..4e85961e1 --- /dev/null +++ b/packages/binding-parser/test/unit/data/too-many-spaces/ast.json @@ -0,0 +1,105 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key01", + "range": "[(0,2)..(0,7)]", + "originalText": "key01" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,7)..(0,8)]" + }, + "value": { + "type": "string-value", + "text": "'value-01'", + "range": "[(0,10)..(0,20)]" + }, + "range": "[(0,2)..(0,20)]", + "type": "structure-element" + }, + { + "key": { + "type": "key", + "text": "key02", + "range": "[(0,29)..(0,34)]", + "originalText": "key02" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,37)..(0,38)]" + }, + "value": { + "type": "string-value", + "text": "'value-02'", + "range": "[(0,42)..(0,52)]" + }, + "range": "[(0,29)..(0,52)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,58)..(0,59)]" + }, + "range": "[(0,0)..(0,59)]", + "commas": [ + { + "type": "comma", + "text": ",", + "range": "[(0,24)..(0,25)]" + } + ], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,1)..(0,2)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,8)..(0,10)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,20)..(0,24)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,25)..(0,29)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,34)..(0,37)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,38)..(0,42)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,52)..(0,58)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/too-many-spaces/cst.json b/packages/binding-parser/test/unit/data/too-many-spaces/cst.json new file mode 100644 index 000000000..26283ec12 --- /dev/null +++ b/packages/binding-parser/test/unit/data/too-many-spaces/cst.json @@ -0,0 +1,134 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key01", + "startColumn": 3, + "endColumn": 7, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 8, + "endColumn": 8, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'value-01'", + "startColumn": 11, + "endColumn": 20, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 11, + "endColumn": 20 + } + } + ] + }, + "location": { + "startColumn": 3, + "endColumn": 20 + } + }, + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key02", + "startColumn": 30, + "endColumn": 34, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 38, + "endColumn": 38, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'value-02'", + "startColumn": 43, + "endColumn": 52, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 43, + "endColumn": 52 + } + } + ] + }, + "location": { + "startColumn": 30, + "endColumn": 52 + } + } + ], + "comma": [ + { + "image": ",", + "startColumn": 25, + "endColumn": 25, + "tokenTypeName": "comma" + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 59, + "endColumn": 59, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 59 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 59 + } +} diff --git a/packages/binding-parser/test/unit/data/too-many-spaces/input.txt b/packages/binding-parser/test/unit/data/too-many-spaces/input.txt new file mode 100644 index 000000000..19c592556 --- /dev/null +++ b/packages/binding-parser/test/unit/data/too-many-spaces/input.txt @@ -0,0 +1 @@ +{ key01: 'value-01' , key02 : 'value-02' } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/too-many-spaces/lexer-errors.json b/packages/binding-parser/test/unit/data/too-many-spaces/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/too-many-spaces/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/too-many-spaces/parse-errors.json b/packages/binding-parser/test/unit/data/too-many-spaces/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/too-many-spaces/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/unknown/ast.json b/packages/binding-parser/test/unit/data/unknown/ast.json new file mode 100644 index 000000000..097eed3df --- /dev/null +++ b/packages/binding-parser/test/unit/data/unknown/ast.json @@ -0,0 +1,45 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,1)..(0,4)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,4)..(0,5)]" + }, + "value": "undefined", + "range": "[(0,1)..(0,5)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,7)..(0,8)]" + }, + "range": "[(0,0)..(0,8)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,5)..(0,6)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/unknown/cst.json b/packages/binding-parser/test/unit/data/unknown/cst.json new file mode 100644 index 000000000..b2cc54e07 --- /dev/null +++ b/packages/binding-parser/test/unit/data/unknown/cst.json @@ -0,0 +1,75 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 2, + "endColumn": 4, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 5, + "endColumn": 5, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": {}, + "location": { + "startColumn": -1, + "endColumn": -1 + }, + "recoveredNode": true + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 5 + }, + "recoveredNode": true + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 8, + "endColumn": 8, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 8 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 8 + } +} diff --git a/packages/binding-parser/test/unit/data/unknown/input.txt b/packages/binding-parser/test/unit/data/unknown/input.txt new file mode 100644 index 000000000..962a4e49c --- /dev/null +++ b/packages/binding-parser/test/unit/data/unknown/input.txt @@ -0,0 +1 @@ +{key: #} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/unknown/lexer-errors.json b/packages/binding-parser/test/unit/data/unknown/lexer-errors.json new file mode 100644 index 000000000..b67815be6 --- /dev/null +++ b/packages/binding-parser/test/unit/data/unknown/lexer-errors.json @@ -0,0 +1,7 @@ +[ + { + "type": "special-chars", + "text": "#", + "range": "[(0,6)..(0,7)]" + } +] diff --git a/packages/binding-parser/test/unit/data/unknown/parse-errors.json b/packages/binding-parser/test/unit/data/unknown/parse-errors.json new file mode 100644 index 000000000..125a59f76 --- /dev/null +++ b/packages/binding-parser/test/unit/data/unknown/parse-errors.json @@ -0,0 +1,23 @@ +[ + { + "type": "parse-error", + "range": "[(0,7)..(0,8)]", + "text": "}", + "merged": [ + { + "type": "parse-error", + "text": "}", + "range": "[(0,7)..(0,8)]", + "tokenTypeName": "right-curly" + } + ], + "tokenTypeName": "right-curly", + "previousToken": { + "type": "parse-error", + "text": ":", + "range": "[(0,4)..(0,5)]", + "tokenTypeName": "colon" + }, + "message": "Expecting: one of these possible Token sequences:\n 1. [string-value]\n 2. [number-value]\n 3. [{]\n 4. [[]\n 5. [boolean-value]\n 6. [null-value]\nbut found: '}'" + } +] diff --git a/packages/binding-parser/test/unit/data/value/boolean-value/ast.json b/packages/binding-parser/test/unit/data/value/boolean-value/ast.json new file mode 100644 index 000000000..1cfc7504b --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/boolean-value/ast.json @@ -0,0 +1,59 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,2)..(0,5)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,5)..(0,6)]" + }, + "value": { + "type": "boolean-value", + "text": "true", + "range": "[(0,7)..(0,11)]" + }, + "range": "[(0,2)..(0,11)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,12)..(0,13)]" + }, + "range": "[(0,0)..(0,13)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,1)..(0,2)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,6)..(0,7)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,11)..(0,12)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/value/boolean-value/cst.json b/packages/binding-parser/test/unit/data/value/boolean-value/cst.json new file mode 100644 index 000000000..49601838f --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/boolean-value/cst.json @@ -0,0 +1,82 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 3, + "endColumn": 5, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 6, + "endColumn": 6, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "boolean-value": [ + { + "image": "true", + "startColumn": 8, + "endColumn": 11, + "tokenTypeName": "boolean-value" + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 11 + } + } + ] + }, + "location": { + "startColumn": 3, + "endColumn": 11 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 13, + "endColumn": 13, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 13 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 13 + } +} diff --git a/packages/binding-parser/test/unit/data/value/boolean-value/input.txt b/packages/binding-parser/test/unit/data/value/boolean-value/input.txt new file mode 100644 index 000000000..7f6a690fa --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/boolean-value/input.txt @@ -0,0 +1 @@ +{ key: true } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/value/boolean-value/lexer-errors.json b/packages/binding-parser/test/unit/data/value/boolean-value/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/boolean-value/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/boolean-value/parse-errors.json b/packages/binding-parser/test/unit/data/value/boolean-value/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/boolean-value/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/collection/boolean-value/ast.json b/packages/binding-parser/test/unit/data/value/collection/boolean-value/ast.json new file mode 100644 index 000000000..132cb65c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/boolean-value/ast.json @@ -0,0 +1,76 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,2)..(0,5)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,5)..(0,6)]" + }, + "value": { + "leftSquare": { + "type": "left-square", + "text": "[", + "range": "[(0,7)..(0,8)]" + }, + "elements": [ + { + "type": "boolean-value", + "text": "true", + "range": "[(0,8)..(0,12)]" + } + ], + "rightSquare": { + "type": "right-square", + "text": "]", + "range": "[(0,12)..(0,13)]" + }, + "range": "[(0,7)..(0,13)]", + "commas": [], + "type": "collection-value" + }, + "range": "[(0,2)..(0,13)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,14)..(0,15)]" + }, + "range": "[(0,0)..(0,15)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,1)..(0,2)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,6)..(0,7)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,13)..(0,14)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/value/collection/boolean-value/cst.json b/packages/binding-parser/test/unit/data/value/collection/boolean-value/cst.json new file mode 100644 index 000000000..a3cfd0b68 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/boolean-value/cst.json @@ -0,0 +1,120 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 3, + "endColumn": 5, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 6, + "endColumn": 6, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "array": [ + { + "name": "array", + "children": { + "left-square": [ + { + "image": "[", + "startColumn": 8, + "endColumn": 8, + "tokenTypeName": "left-square" + } + ], + "value": [ + { + "name": "value", + "children": { + "boolean-value": [ + { + "image": "true", + "startColumn": 9, + "endColumn": 12, + "tokenTypeName": "boolean-value" + } + ] + }, + "location": { + "startColumn": 9, + "endColumn": 12 + } + } + ], + "right-square": [ + { + "image": "]", + "startColumn": 13, + "endColumn": 13, + "tokenTypeName": "right-square" + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 13 + } + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 13 + } + } + ] + }, + "location": { + "startColumn": 3, + "endColumn": 13 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 15, + "endColumn": 15, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 15 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 15 + } +} diff --git a/packages/binding-parser/test/unit/data/value/collection/boolean-value/input.txt b/packages/binding-parser/test/unit/data/value/collection/boolean-value/input.txt new file mode 100644 index 000000000..69313b2d2 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/boolean-value/input.txt @@ -0,0 +1 @@ +{ key: [true] } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/value/collection/boolean-value/lexer-errors.json b/packages/binding-parser/test/unit/data/value/collection/boolean-value/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/boolean-value/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/collection/boolean-value/parse-errors.json b/packages/binding-parser/test/unit/data/value/collection/boolean-value/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/boolean-value/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/collection/empty/ast.json b/packages/binding-parser/test/unit/data/value/collection/empty/ast.json new file mode 100644 index 000000000..24ffff964 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/empty/ast.json @@ -0,0 +1,70 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,2)..(0,5)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,5)..(0,6)]" + }, + "value": { + "leftSquare": { + "type": "left-square", + "text": "[", + "range": "[(0,7)..(0,8)]" + }, + "elements": [], + "rightSquare": { + "type": "right-square", + "text": "]", + "range": "[(0,8)..(0,9)]" + }, + "range": "[(0,7)..(0,9)]", + "commas": [], + "type": "collection-value" + }, + "range": "[(0,2)..(0,9)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,10)..(0,11)]" + }, + "range": "[(0,0)..(0,11)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,1)..(0,2)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,6)..(0,7)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,9)..(0,10)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/value/collection/empty/cst.json b/packages/binding-parser/test/unit/data/value/collection/empty/cst.json new file mode 100644 index 000000000..8fd4fce73 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/empty/cst.json @@ -0,0 +1,101 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 3, + "endColumn": 5, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 6, + "endColumn": 6, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "array": [ + { + "name": "array", + "children": { + "left-square": [ + { + "image": "[", + "startColumn": 8, + "endColumn": 8, + "tokenTypeName": "left-square" + } + ], + "right-square": [ + { + "image": "]", + "startColumn": 9, + "endColumn": 9, + "tokenTypeName": "right-square" + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 9 + } + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 9 + } + } + ] + }, + "location": { + "startColumn": 3, + "endColumn": 9 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 11, + "endColumn": 11, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 11 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 11 + } +} diff --git a/packages/binding-parser/test/unit/data/value/collection/empty/input.txt b/packages/binding-parser/test/unit/data/value/collection/empty/input.txt new file mode 100644 index 000000000..9f6eec26a --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/empty/input.txt @@ -0,0 +1 @@ +{ key: [] } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/value/collection/empty/lexer-errors.json b/packages/binding-parser/test/unit/data/value/collection/empty/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/empty/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/collection/empty/parse-errors.json b/packages/binding-parser/test/unit/data/value/collection/empty/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/empty/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/collection/missing-left-bracket/ast.json b/packages/binding-parser/test/unit/data/value/collection/missing-left-bracket/ast.json new file mode 100644 index 000000000..097eed3df --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/missing-left-bracket/ast.json @@ -0,0 +1,45 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,1)..(0,4)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,4)..(0,5)]" + }, + "value": "undefined", + "range": "[(0,1)..(0,5)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,7)..(0,8)]" + }, + "range": "[(0,0)..(0,8)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,5)..(0,6)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/value/collection/missing-left-bracket/cst.json b/packages/binding-parser/test/unit/data/value/collection/missing-left-bracket/cst.json new file mode 100644 index 000000000..b2cc54e07 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/missing-left-bracket/cst.json @@ -0,0 +1,75 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 2, + "endColumn": 4, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 5, + "endColumn": 5, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": {}, + "location": { + "startColumn": -1, + "endColumn": -1 + }, + "recoveredNode": true + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 5 + }, + "recoveredNode": true + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 8, + "endColumn": 8, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 8 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 8 + } +} diff --git a/packages/binding-parser/test/unit/data/value/collection/missing-left-bracket/input.txt b/packages/binding-parser/test/unit/data/value/collection/missing-left-bracket/input.txt new file mode 100644 index 000000000..626c16d6d --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/missing-left-bracket/input.txt @@ -0,0 +1 @@ +{key: ]} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/value/collection/missing-left-bracket/lexer-errors.json b/packages/binding-parser/test/unit/data/value/collection/missing-left-bracket/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/missing-left-bracket/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/collection/missing-left-bracket/parse-errors.json b/packages/binding-parser/test/unit/data/value/collection/missing-left-bracket/parse-errors.json new file mode 100644 index 000000000..6ef9ff060 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/missing-left-bracket/parse-errors.json @@ -0,0 +1,23 @@ +[ + { + "type": "parse-error", + "range": "[(0,6)..(0,7)]", + "text": "]", + "merged": [ + { + "type": "parse-error", + "text": "]", + "range": "[(0,6)..(0,7)]", + "tokenTypeName": "right-square" + } + ], + "tokenTypeName": "right-square", + "previousToken": { + "type": "parse-error", + "text": ":", + "range": "[(0,4)..(0,5)]", + "tokenTypeName": "colon" + }, + "message": "Expecting: one of these possible Token sequences:\n 1. [string-value]\n 2. [number-value]\n 3. [{]\n 4. [[]\n 5. [boolean-value]\n 6. [null-value]\nbut found: ']'" + } +] diff --git a/packages/binding-parser/test/unit/data/value/collection/missing-right-bracket/ast.json b/packages/binding-parser/test/unit/data/value/collection/missing-right-bracket/ast.json new file mode 100644 index 000000000..bf96711b4 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/missing-right-bracket/ast.json @@ -0,0 +1,60 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,1)..(0,4)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,4)..(0,5)]" + }, + "value": { + "leftSquare": { + "type": "left-square", + "text": "[", + "range": "[(0,6)..(0,7)]" + }, + "elements": [], + "rightSquare": { + "type": "right-square", + "text": "", + "range": "[(0,0)..(0,0)]" + }, + "range": "[(0,6)..(0,7)]", + "commas": [], + "type": "collection-value" + }, + "range": "[(0,1)..(0,7)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,7)..(0,8)]" + }, + "range": "[(0,0)..(0,8)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,5)..(0,6)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/value/collection/missing-right-bracket/cst.json b/packages/binding-parser/test/unit/data/value/collection/missing-right-bracket/cst.json new file mode 100644 index 000000000..b11a97383 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/missing-right-bracket/cst.json @@ -0,0 +1,102 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 2, + "endColumn": 4, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 5, + "endColumn": 5, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "array": [ + { + "name": "array", + "children": { + "left-square": [ + { + "image": "[", + "startColumn": 7, + "endColumn": 7, + "tokenTypeName": "left-square" + } + ], + "right-square": [ + { + "image": "", + "startColumn": -1, + "endColumn": -1, + "isInsertedInRecovery": true, + "tokenTypeName": "right-square" + } + ] + }, + "location": { + "startColumn": 7, + "endColumn": 7 + } + } + ] + }, + "location": { + "startColumn": 7, + "endColumn": 7 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 7 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 8, + "endColumn": 8, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 8 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 8 + } +} diff --git a/packages/binding-parser/test/unit/data/value/collection/missing-right-bracket/input.txt b/packages/binding-parser/test/unit/data/value/collection/missing-right-bracket/input.txt new file mode 100644 index 000000000..1339a17a8 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/missing-right-bracket/input.txt @@ -0,0 +1 @@ +{key: [} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/value/collection/missing-right-bracket/lexer-errors.json b/packages/binding-parser/test/unit/data/value/collection/missing-right-bracket/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/missing-right-bracket/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/collection/missing-right-bracket/parse-errors.json b/packages/binding-parser/test/unit/data/value/collection/missing-right-bracket/parse-errors.json new file mode 100644 index 000000000..3761e1098 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/missing-right-bracket/parse-errors.json @@ -0,0 +1,23 @@ +[ + { + "type": "parse-error", + "range": "[(0,7)..(0,8)]", + "text": "}", + "merged": [ + { + "type": "parse-error", + "text": "}", + "range": "[(0,7)..(0,8)]", + "tokenTypeName": "right-curly" + } + ], + "tokenTypeName": "right-curly", + "previousToken": { + "type": "parse-error", + "text": "[", + "range": "[(0,6)..(0,7)]", + "tokenTypeName": "left-square" + }, + "message": "Expecting --> ] <-- but found --> '}' <--" + } +] diff --git a/packages/binding-parser/test/unit/data/value/collection/nested/ast.json b/packages/binding-parser/test/unit/data/value/collection/nested/ast.json new file mode 100644 index 000000000..89e260ec5 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/nested/ast.json @@ -0,0 +1,87 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,2)..(0,5)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,5)..(0,6)]" + }, + "value": { + "leftSquare": { + "type": "left-square", + "text": "[", + "range": "[(0,7)..(0,8)]" + }, + "elements": [ + { + "leftSquare": { + "type": "left-square", + "text": "[", + "range": "[(0,8)..(0,9)]" + }, + "elements": [], + "rightSquare": { + "type": "right-square", + "text": "]", + "range": "[(0,9)..(0,10)]" + }, + "range": "[(0,8)..(0,10)]", + "commas": [], + "type": "collection-value" + } + ], + "rightSquare": { + "type": "right-square", + "text": "]", + "range": "[(0,10)..(0,11)]" + }, + "range": "[(0,7)..(0,11)]", + "commas": [], + "type": "collection-value" + }, + "range": "[(0,2)..(0,11)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,12)..(0,13)]" + }, + "range": "[(0,0)..(0,13)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,1)..(0,2)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,6)..(0,7)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,11)..(0,12)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/value/collection/nested/cst.json b/packages/binding-parser/test/unit/data/value/collection/nested/cst.json new file mode 100644 index 000000000..59eca2ba5 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/nested/cst.json @@ -0,0 +1,139 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 3, + "endColumn": 5, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 6, + "endColumn": 6, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "array": [ + { + "name": "array", + "children": { + "left-square": [ + { + "image": "[", + "startColumn": 8, + "endColumn": 8, + "tokenTypeName": "left-square" + } + ], + "value": [ + { + "name": "value", + "children": { + "array": [ + { + "name": "array", + "children": { + "left-square": [ + { + "image": "[", + "startColumn": 9, + "endColumn": 9, + "tokenTypeName": "left-square" + } + ], + "right-square": [ + { + "image": "]", + "startColumn": 10, + "endColumn": 10, + "tokenTypeName": "right-square" + } + ] + }, + "location": { + "startColumn": 9, + "endColumn": 10 + } + } + ] + }, + "location": { + "startColumn": 9, + "endColumn": 10 + } + } + ], + "right-square": [ + { + "image": "]", + "startColumn": 11, + "endColumn": 11, + "tokenTypeName": "right-square" + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 11 + } + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 11 + } + } + ] + }, + "location": { + "startColumn": 3, + "endColumn": 11 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 13, + "endColumn": 13, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 13 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 13 + } +} diff --git a/packages/binding-parser/test/unit/data/value/collection/nested/input.txt b/packages/binding-parser/test/unit/data/value/collection/nested/input.txt new file mode 100644 index 000000000..0e249ae5e --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/nested/input.txt @@ -0,0 +1 @@ +{ key: [[]] } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/value/collection/nested/lexer-errors.json b/packages/binding-parser/test/unit/data/value/collection/nested/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/nested/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/collection/nested/parse-errors.json b/packages/binding-parser/test/unit/data/value/collection/nested/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/nested/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/collection/null-value/ast.json b/packages/binding-parser/test/unit/data/value/collection/null-value/ast.json new file mode 100644 index 000000000..a26509caf --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/null-value/ast.json @@ -0,0 +1,76 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,2)..(0,5)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,5)..(0,6)]" + }, + "value": { + "leftSquare": { + "type": "left-square", + "text": "[", + "range": "[(0,7)..(0,8)]" + }, + "elements": [ + { + "type": "null-value", + "text": "null", + "range": "[(0,8)..(0,12)]" + } + ], + "rightSquare": { + "type": "right-square", + "text": "]", + "range": "[(0,12)..(0,13)]" + }, + "range": "[(0,7)..(0,13)]", + "commas": [], + "type": "collection-value" + }, + "range": "[(0,2)..(0,13)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,14)..(0,15)]" + }, + "range": "[(0,0)..(0,15)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,1)..(0,2)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,6)..(0,7)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,13)..(0,14)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/value/collection/null-value/cst.json b/packages/binding-parser/test/unit/data/value/collection/null-value/cst.json new file mode 100644 index 000000000..cc29bf8d9 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/null-value/cst.json @@ -0,0 +1,120 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 3, + "endColumn": 5, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 6, + "endColumn": 6, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "array": [ + { + "name": "array", + "children": { + "left-square": [ + { + "image": "[", + "startColumn": 8, + "endColumn": 8, + "tokenTypeName": "left-square" + } + ], + "value": [ + { + "name": "value", + "children": { + "null-value": [ + { + "image": "null", + "startColumn": 9, + "endColumn": 12, + "tokenTypeName": "null-value" + } + ] + }, + "location": { + "startColumn": 9, + "endColumn": 12 + } + } + ], + "right-square": [ + { + "image": "]", + "startColumn": 13, + "endColumn": 13, + "tokenTypeName": "right-square" + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 13 + } + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 13 + } + } + ] + }, + "location": { + "startColumn": 3, + "endColumn": 13 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 15, + "endColumn": 15, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 15 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 15 + } +} diff --git a/packages/binding-parser/test/unit/data/value/collection/null-value/input.txt b/packages/binding-parser/test/unit/data/value/collection/null-value/input.txt new file mode 100644 index 000000000..c5774f117 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/null-value/input.txt @@ -0,0 +1 @@ +{ key: [null] } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/value/collection/null-value/lexer-errors.json b/packages/binding-parser/test/unit/data/value/collection/null-value/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/null-value/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/collection/null-value/parse-errors.json b/packages/binding-parser/test/unit/data/value/collection/null-value/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/null-value/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/collection/number-value/ast.json b/packages/binding-parser/test/unit/data/value/collection/number-value/ast.json new file mode 100644 index 000000000..31ed2275a --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/number-value/ast.json @@ -0,0 +1,76 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,2)..(0,5)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,5)..(0,6)]" + }, + "value": { + "leftSquare": { + "type": "left-square", + "text": "[", + "range": "[(0,7)..(0,8)]" + }, + "elements": [ + { + "type": "number-value", + "text": "123", + "range": "[(0,8)..(0,11)]" + } + ], + "rightSquare": { + "type": "right-square", + "text": "]", + "range": "[(0,11)..(0,12)]" + }, + "range": "[(0,7)..(0,12)]", + "commas": [], + "type": "collection-value" + }, + "range": "[(0,2)..(0,12)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,13)..(0,14)]" + }, + "range": "[(0,0)..(0,14)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,1)..(0,2)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,6)..(0,7)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,12)..(0,13)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/value/collection/number-value/cst.json b/packages/binding-parser/test/unit/data/value/collection/number-value/cst.json new file mode 100644 index 000000000..4914d2a54 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/number-value/cst.json @@ -0,0 +1,120 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 3, + "endColumn": 5, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 6, + "endColumn": 6, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "array": [ + { + "name": "array", + "children": { + "left-square": [ + { + "image": "[", + "startColumn": 8, + "endColumn": 8, + "tokenTypeName": "left-square" + } + ], + "value": [ + { + "name": "value", + "children": { + "number-value": [ + { + "image": "123", + "startColumn": 9, + "endColumn": 11, + "tokenTypeName": "number-value" + } + ] + }, + "location": { + "startColumn": 9, + "endColumn": 11 + } + } + ], + "right-square": [ + { + "image": "]", + "startColumn": 12, + "endColumn": 12, + "tokenTypeName": "right-square" + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 12 + } + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 12 + } + } + ] + }, + "location": { + "startColumn": 3, + "endColumn": 12 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 14, + "endColumn": 14, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 14 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 14 + } +} diff --git a/packages/binding-parser/test/unit/data/value/collection/number-value/input.txt b/packages/binding-parser/test/unit/data/value/collection/number-value/input.txt new file mode 100644 index 000000000..96c33d330 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/number-value/input.txt @@ -0,0 +1 @@ +{ key: [123] } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/value/collection/number-value/lexer-errors.json b/packages/binding-parser/test/unit/data/value/collection/number-value/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/number-value/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/collection/number-value/parse-errors.json b/packages/binding-parser/test/unit/data/value/collection/number-value/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/number-value/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/collection/string-value/ast.json b/packages/binding-parser/test/unit/data/value/collection/string-value/ast.json new file mode 100644 index 000000000..e84e0ad1d --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/string-value/ast.json @@ -0,0 +1,92 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,2)..(0,5)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,5)..(0,6)]" + }, + "value": { + "leftSquare": { + "type": "left-square", + "text": "[", + "range": "[(0,7)..(0,8)]" + }, + "elements": [ + { + "type": "string-value", + "text": "'value-01'", + "range": "[(0,8)..(0,18)]" + }, + { + "type": "string-value", + "text": "'value-02'", + "range": "[(0,20)..(0,30)]" + } + ], + "rightSquare": { + "type": "right-square", + "text": "]", + "range": "[(0,30)..(0,31)]" + }, + "range": "[(0,7)..(0,31)]", + "commas": [ + { + "type": "comma", + "text": ",", + "range": "[(0,18)..(0,19)]" + } + ], + "type": "collection-value" + }, + "range": "[(0,2)..(0,31)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,32)..(0,33)]" + }, + "range": "[(0,0)..(0,33)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,1)..(0,2)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,6)..(0,7)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,19)..(0,20)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,31)..(0,32)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/value/collection/string-value/cst.json b/packages/binding-parser/test/unit/data/value/collection/string-value/cst.json new file mode 100644 index 000000000..07e9c1471 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/string-value/cst.json @@ -0,0 +1,145 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 3, + "endColumn": 5, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 6, + "endColumn": 6, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "array": [ + { + "name": "array", + "children": { + "left-square": [ + { + "image": "[", + "startColumn": 8, + "endColumn": 8, + "tokenTypeName": "left-square" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'value-01'", + "startColumn": 9, + "endColumn": 18, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 9, + "endColumn": 18 + } + }, + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'value-02'", + "startColumn": 21, + "endColumn": 30, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 21, + "endColumn": 30 + } + } + ], + "comma": [ + { + "image": ",", + "startColumn": 19, + "endColumn": 19, + "tokenTypeName": "comma" + } + ], + "right-square": [ + { + "image": "]", + "startColumn": 31, + "endColumn": 31, + "tokenTypeName": "right-square" + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 31 + } + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 31 + } + } + ] + }, + "location": { + "startColumn": 3, + "endColumn": 31 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 33, + "endColumn": 33, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 33 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 33 + } +} diff --git a/packages/binding-parser/test/unit/data/value/collection/string-value/input.txt b/packages/binding-parser/test/unit/data/value/collection/string-value/input.txt new file mode 100644 index 000000000..695bab713 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/string-value/input.txt @@ -0,0 +1 @@ +{ key: ['value-01', 'value-02'] } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/value/collection/string-value/lexer-errors.json b/packages/binding-parser/test/unit/data/value/collection/string-value/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/string-value/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/collection/string-value/parse-errors.json b/packages/binding-parser/test/unit/data/value/collection/string-value/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/string-value/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/collection/structure/simple/ast.json b/packages/binding-parser/test/unit/data/value/collection/structure/simple/ast.json new file mode 100644 index 000000000..f5c001e9e --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/structure/simple/ast.json @@ -0,0 +1,113 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,2)..(0,5)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,5)..(0,6)]" + }, + "value": { + "leftSquare": { + "type": "left-square", + "text": "[", + "range": "[(0,7)..(0,8)]" + }, + "elements": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,8)..(0,9)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "insideCollectionKey", + "range": "[(0,9)..(0,28)]", + "originalText": "insideCollectionKey" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,28)..(0,29)]" + }, + "value": { + "type": "string-value", + "text": "'inside collection value'", + "range": "[(0,30)..(0,55)]" + }, + "range": "[(0,9)..(0,55)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,55)..(0,56)]" + }, + "range": "[(0,8)..(0,56)]", + "commas": [], + "type": "structure-value" + } + ], + "rightSquare": { + "type": "right-square", + "text": "]", + "range": "[(0,56)..(0,57)]" + }, + "range": "[(0,7)..(0,57)]", + "commas": [], + "type": "collection-value" + }, + "range": "[(0,2)..(0,57)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,58)..(0,59)]" + }, + "range": "[(0,0)..(0,59)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,1)..(0,2)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,6)..(0,7)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,29)..(0,30)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,57)..(0,58)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/value/collection/structure/simple/cst.json b/packages/binding-parser/test/unit/data/value/collection/structure/simple/cst.json new file mode 100644 index 000000000..e43c442f1 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/structure/simple/cst.json @@ -0,0 +1,185 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 3, + "endColumn": 5, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 6, + "endColumn": 6, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "array": [ + { + "name": "array", + "children": { + "left-square": [ + { + "image": "[", + "startColumn": 8, + "endColumn": 8, + "tokenTypeName": "left-square" + } + ], + "value": [ + { + "name": "value", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 9, + "endColumn": 9, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "insideCollectionKey", + "startColumn": 10, + "endColumn": 28, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 29, + "endColumn": 29, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'inside collection value'", + "startColumn": 31, + "endColumn": 55, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 31, + "endColumn": 55 + } + } + ] + }, + "location": { + "startColumn": 10, + "endColumn": 55 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 56, + "endColumn": 56, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 9, + "endColumn": 56 + } + } + ] + }, + "location": { + "startColumn": 9, + "endColumn": 56 + } + } + ], + "right-square": [ + { + "image": "]", + "startColumn": 57, + "endColumn": 57, + "tokenTypeName": "right-square" + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 57 + } + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 57 + } + } + ] + }, + "location": { + "startColumn": 3, + "endColumn": 57 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 59, + "endColumn": 59, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 59 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 59 + } +} diff --git a/packages/binding-parser/test/unit/data/value/collection/structure/simple/input.txt b/packages/binding-parser/test/unit/data/value/collection/structure/simple/input.txt new file mode 100644 index 000000000..af15a76b2 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/structure/simple/input.txt @@ -0,0 +1 @@ +{ key: [{insideCollectionKey: 'inside collection value'}] } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/value/collection/structure/simple/lexer-errors.json b/packages/binding-parser/test/unit/data/value/collection/structure/simple/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/structure/simple/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/collection/structure/simple/parse-errors.json b/packages/binding-parser/test/unit/data/value/collection/structure/simple/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/collection/structure/simple/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/null-value/ast.json b/packages/binding-parser/test/unit/data/value/null-value/ast.json new file mode 100644 index 000000000..759b242dc --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/null-value/ast.json @@ -0,0 +1,59 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,2)..(0,5)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,5)..(0,6)]" + }, + "value": { + "type": "null-value", + "text": "null", + "range": "[(0,7)..(0,11)]" + }, + "range": "[(0,2)..(0,11)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,12)..(0,13)]" + }, + "range": "[(0,0)..(0,13)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,1)..(0,2)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,6)..(0,7)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,11)..(0,12)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/value/null-value/cst.json b/packages/binding-parser/test/unit/data/value/null-value/cst.json new file mode 100644 index 000000000..04a9f16c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/null-value/cst.json @@ -0,0 +1,82 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 3, + "endColumn": 5, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 6, + "endColumn": 6, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "null-value": [ + { + "image": "null", + "startColumn": 8, + "endColumn": 11, + "tokenTypeName": "null-value" + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 11 + } + } + ] + }, + "location": { + "startColumn": 3, + "endColumn": 11 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 13, + "endColumn": 13, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 13 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 13 + } +} diff --git a/packages/binding-parser/test/unit/data/value/null-value/input.txt b/packages/binding-parser/test/unit/data/value/null-value/input.txt new file mode 100644 index 000000000..693765176 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/null-value/input.txt @@ -0,0 +1 @@ +{ key: null } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/value/null-value/lexer-errors.json b/packages/binding-parser/test/unit/data/value/null-value/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/null-value/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/null-value/parse-errors.json b/packages/binding-parser/test/unit/data/value/null-value/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/null-value/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/number-value/ast.json b/packages/binding-parser/test/unit/data/value/number-value/ast.json new file mode 100644 index 000000000..e2d5d9f9f --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/number-value/ast.json @@ -0,0 +1,59 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,2)..(0,5)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,5)..(0,6)]" + }, + "value": { + "type": "number-value", + "text": "123", + "range": "[(0,7)..(0,10)]" + }, + "range": "[(0,2)..(0,10)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,11)..(0,12)]" + }, + "range": "[(0,0)..(0,12)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,1)..(0,2)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,6)..(0,7)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,10)..(0,11)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/value/number-value/cst.json b/packages/binding-parser/test/unit/data/value/number-value/cst.json new file mode 100644 index 000000000..8a16a32d3 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/number-value/cst.json @@ -0,0 +1,82 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 3, + "endColumn": 5, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 6, + "endColumn": 6, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "number-value": [ + { + "image": "123", + "startColumn": 8, + "endColumn": 10, + "tokenTypeName": "number-value" + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 10 + } + } + ] + }, + "location": { + "startColumn": 3, + "endColumn": 10 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 12, + "endColumn": 12, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 12 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 12 + } +} diff --git a/packages/binding-parser/test/unit/data/value/number-value/input.txt b/packages/binding-parser/test/unit/data/value/number-value/input.txt new file mode 100644 index 000000000..7d3c5db01 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/number-value/input.txt @@ -0,0 +1 @@ +{ key: 123 } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/value/number-value/lexer-errors.json b/packages/binding-parser/test/unit/data/value/number-value/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/number-value/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/number-value/parse-errors.json b/packages/binding-parser/test/unit/data/value/number-value/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/number-value/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/string-value/ast.json b/packages/binding-parser/test/unit/data/value/string-value/ast.json new file mode 100644 index 000000000..cf59e0044 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/string-value/ast.json @@ -0,0 +1,59 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,2)..(0,5)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,5)..(0,6)]" + }, + "value": { + "type": "string-value", + "text": "'value-02'", + "range": "[(0,7)..(0,17)]" + }, + "range": "[(0,2)..(0,17)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,18)..(0,19)]" + }, + "range": "[(0,0)..(0,19)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,1)..(0,2)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,6)..(0,7)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,17)..(0,18)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/value/string-value/cst.json b/packages/binding-parser/test/unit/data/value/string-value/cst.json new file mode 100644 index 000000000..24df9860f --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/string-value/cst.json @@ -0,0 +1,82 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 3, + "endColumn": 5, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 6, + "endColumn": 6, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'value-02'", + "startColumn": 8, + "endColumn": 17, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 17 + } + } + ] + }, + "location": { + "startColumn": 3, + "endColumn": 17 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 19, + "endColumn": 19, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 19 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 19 + } +} diff --git a/packages/binding-parser/test/unit/data/value/string-value/input.txt b/packages/binding-parser/test/unit/data/value/string-value/input.txt new file mode 100644 index 000000000..571b49b61 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/string-value/input.txt @@ -0,0 +1 @@ +{ key: 'value-02' } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/value/string-value/lexer-errors.json b/packages/binding-parser/test/unit/data/value/string-value/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/string-value/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/string-value/parse-errors.json b/packages/binding-parser/test/unit/data/value/string-value/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/string-value/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/structure/empty/ast.json b/packages/binding-parser/test/unit/data/value/structure/empty/ast.json new file mode 100644 index 000000000..df0127633 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/empty/ast.json @@ -0,0 +1,70 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,2)..(0,5)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,5)..(0,6)]" + }, + "value": { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,7)..(0,8)]" + }, + "elements": [], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,8)..(0,9)]" + }, + "range": "[(0,7)..(0,9)]", + "commas": [], + "type": "structure-value" + }, + "range": "[(0,2)..(0,9)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,10)..(0,11)]" + }, + "range": "[(0,0)..(0,11)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,1)..(0,2)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,6)..(0,7)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,9)..(0,10)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/value/structure/empty/cst.json b/packages/binding-parser/test/unit/data/value/structure/empty/cst.json new file mode 100644 index 000000000..ce5278220 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/empty/cst.json @@ -0,0 +1,101 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 3, + "endColumn": 5, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 6, + "endColumn": 6, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 8, + "endColumn": 8, + "tokenTypeName": "left-curly" + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 9, + "endColumn": 9, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 9 + } + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 9 + } + } + ] + }, + "location": { + "startColumn": 3, + "endColumn": 9 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 11, + "endColumn": 11, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 11 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 11 + } +} diff --git a/packages/binding-parser/test/unit/data/value/structure/empty/input.txt b/packages/binding-parser/test/unit/data/value/structure/empty/input.txt new file mode 100644 index 000000000..ebc5fb2b8 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/empty/input.txt @@ -0,0 +1 @@ +{ key: {} } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/value/structure/empty/lexer-errors.json b/packages/binding-parser/test/unit/data/value/structure/empty/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/empty/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/structure/empty/parse-errors.json b/packages/binding-parser/test/unit/data/value/structure/empty/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/empty/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/structure/missing-left-curly/ast.json b/packages/binding-parser/test/unit/data/value/structure/missing-left-curly/ast.json new file mode 100644 index 000000000..a12b9709b --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/missing-left-curly/ast.json @@ -0,0 +1,81 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,1)..(0,4)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,4)..(0,5)]" + }, + "value": { + "type": "string-value", + "text": "'value'", + "range": "[(0,6)..(0,13)]" + }, + "range": "[(0,1)..(0,13)]", + "type": "structure-element" + }, + { + "key": { + "type": "key", + "text": "anotherKey", + "range": "[(0,15)..(0,25)]", + "originalText": "anotherKey" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,25)..(0,26)]" + }, + "value": "undefined", + "range": "[(0,15)..(0,26)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,27)..(0,28)]" + }, + "range": "[(0,0)..(0,28)]", + "commas": [ + { + "type": "comma", + "text": ",", + "range": "[(0,13)..(0,14)]" + } + ], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,5)..(0,6)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,14)..(0,15)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,26)..(0,27)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/value/structure/missing-left-curly/cst.json b/packages/binding-parser/test/unit/data/value/structure/missing-left-curly/cst.json new file mode 100644 index 000000000..f21a0d962 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/missing-left-curly/cst.json @@ -0,0 +1,127 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 2, + "endColumn": 4, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 5, + "endColumn": 5, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'value'", + "startColumn": 7, + "endColumn": 13, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 7, + "endColumn": 13 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 13 + } + }, + { + "name": "object-item", + "children": { + "key": [ + { + "image": "anotherKey", + "startColumn": 16, + "endColumn": 25, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 26, + "endColumn": 26, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": {}, + "location": { + "startColumn": -1, + "endColumn": -1 + }, + "recoveredNode": true + } + ] + }, + "location": { + "startColumn": 16, + "endColumn": 26 + }, + "recoveredNode": true + } + ], + "comma": [ + { + "image": ",", + "startColumn": 14, + "endColumn": 14, + "tokenTypeName": "comma" + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 28, + "endColumn": 28, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 28 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 28 + } +} diff --git a/packages/binding-parser/test/unit/data/value/structure/missing-left-curly/input.txt b/packages/binding-parser/test/unit/data/value/structure/missing-left-curly/input.txt new file mode 100644 index 000000000..d8dd36a65 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/missing-left-curly/input.txt @@ -0,0 +1 @@ +{key: 'value', anotherKey: }} \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/value/structure/missing-left-curly/lexer-errors.json b/packages/binding-parser/test/unit/data/value/structure/missing-left-curly/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/missing-left-curly/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/structure/missing-left-curly/parse-errors.json b/packages/binding-parser/test/unit/data/value/structure/missing-left-curly/parse-errors.json new file mode 100644 index 000000000..734c2d448 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/missing-left-curly/parse-errors.json @@ -0,0 +1,39 @@ +[ + { + "type": "parse-error", + "range": "[(0,27)..(0,28)]", + "text": "}", + "merged": [ + { + "type": "parse-error", + "text": "}", + "range": "[(0,27)..(0,28)]", + "tokenTypeName": "right-curly" + } + ], + "tokenTypeName": "right-curly", + "previousToken": { + "type": "parse-error", + "text": ":", + "range": "[(0,25)..(0,26)]", + "tokenTypeName": "colon" + }, + "message": "Expecting: one of these possible Token sequences:\n 1. [string-value]\n 2. [number-value]\n 3. [{]\n 4. [[]\n 5. [boolean-value]\n 6. [null-value]\nbut found: '}'" + }, + { + "type": "parse-error", + "range": "[(0,28)..(0,29)]", + "text": "}", + "merged": [ + { + "type": "parse-error", + "text": "}", + "range": "[(0,28)..(0,29)]", + "tokenTypeName": "right-curly" + } + ], + "tokenTypeName": "right-curly", + "previousToken": "undefined", + "message": "Redundant input, expecting EOF but found: }" + } +] diff --git a/packages/binding-parser/test/unit/data/value/structure/missing-right-curly/ast.json b/packages/binding-parser/test/unit/data/value/structure/missing-right-curly/ast.json new file mode 100644 index 000000000..a12b9709b --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/missing-right-curly/ast.json @@ -0,0 +1,81 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,1)..(0,4)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,4)..(0,5)]" + }, + "value": { + "type": "string-value", + "text": "'value'", + "range": "[(0,6)..(0,13)]" + }, + "range": "[(0,1)..(0,13)]", + "type": "structure-element" + }, + { + "key": { + "type": "key", + "text": "anotherKey", + "range": "[(0,15)..(0,25)]", + "originalText": "anotherKey" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,25)..(0,26)]" + }, + "value": "undefined", + "range": "[(0,15)..(0,26)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,27)..(0,28)]" + }, + "range": "[(0,0)..(0,28)]", + "commas": [ + { + "type": "comma", + "text": ",", + "range": "[(0,13)..(0,14)]" + } + ], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,5)..(0,6)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,14)..(0,15)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,26)..(0,27)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/value/structure/missing-right-curly/cst.json b/packages/binding-parser/test/unit/data/value/structure/missing-right-curly/cst.json new file mode 100644 index 000000000..f21a0d962 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/missing-right-curly/cst.json @@ -0,0 +1,127 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 2, + "endColumn": 4, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 5, + "endColumn": 5, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'value'", + "startColumn": 7, + "endColumn": 13, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 7, + "endColumn": 13 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 13 + } + }, + { + "name": "object-item", + "children": { + "key": [ + { + "image": "anotherKey", + "startColumn": 16, + "endColumn": 25, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 26, + "endColumn": 26, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": {}, + "location": { + "startColumn": -1, + "endColumn": -1 + }, + "recoveredNode": true + } + ] + }, + "location": { + "startColumn": 16, + "endColumn": 26 + }, + "recoveredNode": true + } + ], + "comma": [ + { + "image": ",", + "startColumn": 14, + "endColumn": 14, + "tokenTypeName": "comma" + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 28, + "endColumn": 28, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 28 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 28 + } +} diff --git a/packages/binding-parser/test/unit/data/value/structure/missing-right-curly/input.txt b/packages/binding-parser/test/unit/data/value/structure/missing-right-curly/input.txt new file mode 100644 index 000000000..79d6239ef --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/missing-right-curly/input.txt @@ -0,0 +1 @@ +{key: 'value', anotherKey: } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/value/structure/missing-right-curly/lexer-errors.json b/packages/binding-parser/test/unit/data/value/structure/missing-right-curly/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/missing-right-curly/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/structure/missing-right-curly/parse-errors.json b/packages/binding-parser/test/unit/data/value/structure/missing-right-curly/parse-errors.json new file mode 100644 index 000000000..4b9dc3e38 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/missing-right-curly/parse-errors.json @@ -0,0 +1,23 @@ +[ + { + "type": "parse-error", + "range": "[(0,27)..(0,28)]", + "text": "}", + "merged": [ + { + "type": "parse-error", + "text": "}", + "range": "[(0,27)..(0,28)]", + "tokenTypeName": "right-curly" + } + ], + "tokenTypeName": "right-curly", + "previousToken": { + "type": "parse-error", + "text": ":", + "range": "[(0,25)..(0,26)]", + "tokenTypeName": "colon" + }, + "message": "Expecting: one of these possible Token sequences:\n 1. [string-value]\n 2. [number-value]\n 3. [{]\n 4. [[]\n 5. [boolean-value]\n 6. [null-value]\nbut found: '}'" + } +] diff --git a/packages/binding-parser/test/unit/data/value/structure/nested/ast.json b/packages/binding-parser/test/unit/data/value/structure/nested/ast.json new file mode 100644 index 000000000..378510c25 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/nested/ast.json @@ -0,0 +1,107 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,2)..(0,5)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,5)..(0,6)]" + }, + "value": { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,7)..(0,8)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "anotherKey", + "range": "[(0,8)..(0,18)]", + "originalText": "anotherKey" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,18)..(0,19)]" + }, + "value": { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,20)..(0,21)]" + }, + "elements": [], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,21)..(0,22)]" + }, + "range": "[(0,20)..(0,22)]", + "commas": [], + "type": "structure-value" + }, + "range": "[(0,8)..(0,22)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,22)..(0,23)]" + }, + "range": "[(0,7)..(0,23)]", + "commas": [], + "type": "structure-value" + }, + "range": "[(0,2)..(0,23)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,24)..(0,25)]" + }, + "range": "[(0,0)..(0,25)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,1)..(0,2)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,6)..(0,7)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,19)..(0,20)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,23)..(0,24)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/value/structure/nested/cst.json b/packages/binding-parser/test/unit/data/value/structure/nested/cst.json new file mode 100644 index 000000000..adb9cd41d --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/nested/cst.json @@ -0,0 +1,166 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 3, + "endColumn": 5, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 6, + "endColumn": 6, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 8, + "endColumn": 8, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "anotherKey", + "startColumn": 9, + "endColumn": 18, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 19, + "endColumn": 19, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 21, + "endColumn": 21, + "tokenTypeName": "left-curly" + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 22, + "endColumn": 22, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 21, + "endColumn": 22 + } + } + ] + }, + "location": { + "startColumn": 21, + "endColumn": 22 + } + } + ] + }, + "location": { + "startColumn": 9, + "endColumn": 22 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 23, + "endColumn": 23, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 23 + } + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 23 + } + } + ] + }, + "location": { + "startColumn": 3, + "endColumn": 23 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 25, + "endColumn": 25, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 25 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 25 + } +} diff --git a/packages/binding-parser/test/unit/data/value/structure/nested/input.txt b/packages/binding-parser/test/unit/data/value/structure/nested/input.txt new file mode 100644 index 000000000..fbb3ed4b5 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/nested/input.txt @@ -0,0 +1 @@ +{ key: {anotherKey: {}} } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/value/structure/nested/lexer-errors.json b/packages/binding-parser/test/unit/data/value/structure/nested/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/nested/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/structure/nested/parse-errors.json b/packages/binding-parser/test/unit/data/value/structure/nested/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/nested/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/structure/simple/ast.json b/packages/binding-parser/test/unit/data/value/structure/simple/ast.json new file mode 100644 index 000000000..a3d172871 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/simple/ast.json @@ -0,0 +1,96 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "key", + "range": "[(0,2)..(0,5)]", + "originalText": "key" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,5)..(0,6)]" + }, + "value": { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,7)..(0,8)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "anotherKey", + "range": "[(0,8)..(0,18)]", + "originalText": "anotherKey" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,18)..(0,19)]" + }, + "value": { + "type": "string-value", + "text": "'another value'", + "range": "[(0,20)..(0,35)]" + }, + "range": "[(0,8)..(0,35)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,35)..(0,36)]" + }, + "range": "[(0,7)..(0,36)]", + "commas": [], + "type": "structure-value" + }, + "range": "[(0,2)..(0,36)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,37)..(0,38)]" + }, + "range": "[(0,0)..(0,38)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,1)..(0,2)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,6)..(0,7)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,19)..(0,20)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,36)..(0,37)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/value/structure/simple/cst.json b/packages/binding-parser/test/unit/data/value/structure/simple/cst.json new file mode 100644 index 000000000..c6c825c3e --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/simple/cst.json @@ -0,0 +1,147 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "key", + "startColumn": 3, + "endColumn": 5, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 6, + "endColumn": 6, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 8, + "endColumn": 8, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "anotherKey", + "startColumn": 9, + "endColumn": 18, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 19, + "endColumn": 19, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "string-value": [ + { + "image": "'another value'", + "startColumn": 21, + "endColumn": 35, + "tokenTypeName": "string-value" + } + ] + }, + "location": { + "startColumn": 21, + "endColumn": 35 + } + } + ] + }, + "location": { + "startColumn": 9, + "endColumn": 35 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 36, + "endColumn": 36, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 36 + } + } + ] + }, + "location": { + "startColumn": 8, + "endColumn": 36 + } + } + ] + }, + "location": { + "startColumn": 3, + "endColumn": 36 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 38, + "endColumn": 38, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 38 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 38 + } +} diff --git a/packages/binding-parser/test/unit/data/value/structure/simple/input.txt b/packages/binding-parser/test/unit/data/value/structure/simple/input.txt new file mode 100644 index 000000000..b12ff2327 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/simple/input.txt @@ -0,0 +1 @@ +{ key: {anotherKey: 'another value'} } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/value/structure/simple/lexer-errors.json b/packages/binding-parser/test/unit/data/value/structure/simple/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/simple/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/value/structure/simple/parse-errors.json b/packages/binding-parser/test/unit/data/value/structure/simple/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/value/structure/simple/parse-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/helper/deserialize-ast.ts b/packages/binding-parser/test/unit/helper/deserialize-ast.ts new file mode 100644 index 000000000..35a793266 --- /dev/null +++ b/packages/binding-parser/test/unit/helper/deserialize-ast.ts @@ -0,0 +1,51 @@ +import { Range, Position } from "vscode-languageserver-types"; + +/** + * Parses short hand position expression and creates an object from it. + * @param value (line,character) + */ +function expandPosition(value: string): Position { + const [line, character] = value + .substring(1, value.length - 1) + .split(",") + .map((text) => { + if (text === "NaN") { + text = "0"; + } + return parseInt(text, 10); + }); + return Position.create(line, character); +} +/** + * Parses short hand range expression and creates an object from it. + * @param value [(line,character)..(line..character)] + */ +function expandRange(value: string): Range { + const [start, end] = value + .substring(1, value.length - 1) + .split("..") + .map(expandPosition); + return Range.create(start, end); +} + +const rangePropertyPattern = /ranges?/i; + +/** + * Parses JSON text which has short hand notation for ranges + * @param text + */ +export const deserialize = (text: string): T => { + return JSON.parse(text, (key, value) => { + if (value === "NEGATIVE_ZERO") { + return -0; + } + if (rangePropertyPattern.test(key) && typeof value === "string") { + return expandRange(value); + } else if (rangePropertyPattern.test(key) && Array.isArray(value)) { + return value.map((item) => expandRange(item)); + } else if (value === undefined) { + return "undefined"; + } + return value; + }); +}; diff --git a/packages/binding-parser/test/unit/helper/index.ts b/packages/binding-parser/test/unit/helper/index.ts new file mode 100644 index 000000000..07b290475 --- /dev/null +++ b/packages/binding-parser/test/unit/helper/index.ts @@ -0,0 +1,15 @@ +export { + getInput, + getCst, + getAst, + getLexerErrors, + getParserErrors, + getAllNormalizeFolderPath, + getBase, + transformCstForAssertion, + doesExits, + getFileContent, +} from "./setup"; + +export { serialize } from "./serialize"; +export { deserialize } from "./deserialize-ast"; diff --git a/packages/binding-parser/test/unit/helper/serialize.ts b/packages/binding-parser/test/unit/helper/serialize.ts new file mode 100644 index 000000000..7ee7af00a --- /dev/null +++ b/packages/binding-parser/test/unit/helper/serialize.ts @@ -0,0 +1,27 @@ +const rangePropertyPattern = /ranges?/i; +const compactPosition = (position) => + `(${position.line},${position.character})`; +const compactRange = (range) => + `[${compactPosition(range.start)}..${compactPosition(range.end)}]`; + +const compactAst = (key, value) => { + if (value === 0 && 1 / value < 0) { + // when serializing 0 the sign is removed, we need to avoid this lossy transformation + return "NEGATIVE_ZERO"; + } + if (rangePropertyPattern.test(key) && value) { + if (Array.isArray(value)) { + return value.map(compactRange); + } + return compactRange(value); + } + if (value === undefined) { + return "undefined"; + } + return value; +}; + +export const serialize = (value: T): string => { + const text = JSON.stringify(value, compactAst, 2) + "\n"; + return text; +}; diff --git a/packages/binding-parser/test/unit/helper/setup.ts b/packages/binding-parser/test/unit/helper/setup.ts new file mode 100644 index 000000000..aed4f3164 --- /dev/null +++ b/packages/binding-parser/test/unit/helper/setup.ts @@ -0,0 +1,167 @@ +import { promises, readdirSync, stat, statSync } from "fs"; +import { join, dirname } from "path"; +import { platform } from "os"; +import type { IToken, CstNode, CstNodeLocation, CstElement } from "chevrotain"; +import { deserialize } from "./deserialize-ast"; +import type { Template } from "../../../src/types/binding-parser"; + +const { readFile } = promises; + +const hasNaNOrUndefined = (value: undefined | number): boolean => { + if (value === undefined) { + return true; + } + return isNaN(value); +}; + +export const getBase = (): string => { + if (process.env.TEST_UPDATE) { + return join(__dirname, "..", "..", "..", "..", "test", "unit", "data"); + } + return join(__dirname, "..", "..", "..", "test", "unit", "data"); +}; + +export const getFileContent = async (filePath: string): Promise => { + const buffer = await readFile(filePath, "utf8"); + return buffer.toString(); +}; + +export const getInput = async (testCasePath: string): Promise => { + const path = join(getBase(), testCasePath, "input.txt"); + return getFileContent(path); +}; + +export const getCst = async (testCasePath: string): Promise => { + const path = join(getBase(), testCasePath, "cst.json"); + const content = await getFileContent(path); + return deserialize(content); +}; +export const getLexerErrors = async ( + testCasePath: string +): Promise => { + const path = join(getBase(), testCasePath, "lexer-errors.json"); + const content = await getFileContent(path); + return deserialize(content); +}; +export const getParserErrors = async ( + testCasePath: string +): Promise => { + const path = join(getBase(), testCasePath, "parse-errors.json"); + const content = await getFileContent(path); + return deserialize(content); +}; + +export const getAst = async (testCasePath: string): Promise