Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/powerquery-parser/common/stringUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ export function maybeQuotedIdentifier(text: string, index: number): number | und
const startingIndex: number = index;
const textLength: number = text.length;
let continueMatching: boolean = true;
let isValid: boolean = false;
index += 2;

while (continueMatching) {
Expand All @@ -179,7 +178,6 @@ export function maybeQuotedIdentifier(text: string, index: number): number | und

if (chr2 !== '"') {
continueMatching = false;
isValid = true;
index += 1;
continue;
} else {
Expand All @@ -194,7 +192,7 @@ export function maybeQuotedIdentifier(text: string, index: number): number | und
}
}

return isValid ? index - startingIndex : undefined;
return index !== startingIndex ? index - startingIndex : undefined;
}

export function maybeNewlineKindAt(text: string, index: number): NewlineKind | undefined {
Expand Down
15 changes: 15 additions & 0 deletions src/test/libraryTest/common/stringUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,19 @@ describe("StringUtils", () => {
it("a..1", () => expect(StringUtils.isGeneralizedIdentifier("a..1"), "should be false").to.be.false);
});
});

describe(`isQuotedIdentifier`, () => {
describe(`valid`, () => {
it(`#"foo"`, () => expect(StringUtils.isQuotedIdentifier(`#"foo"`), "should be true").to.be.true);
it(`#""`, () => expect(StringUtils.isQuotedIdentifier(`#""`), "should be true").to.be.true);
it(`#""""`, () => expect(StringUtils.isQuotedIdentifier(`#""""`), "should be true").to.be.true);
it(`#"a""b""c"`, () => expect(StringUtils.isQuotedIdentifier(`#"a""b""c"`), "should be true").to.be.true);
it(`#"""b""c"`, () => expect(StringUtils.isQuotedIdentifier(`#"""b""c"`), "should be true").to.be.true);
it(`#"a""b"""`, () => expect(StringUtils.isQuotedIdentifier(`#"a""b"""`), "should be true").to.be.true);
});
describe(`invalid`, () => {
it(`#"`, () => expect(StringUtils.isGeneralizedIdentifier(`#"`), "should be false").to.be.false);
it(`""`, () => expect(StringUtils.isGeneralizedIdentifier(`""`), "should be false").to.be.false);
});
});
});
34 changes: 26 additions & 8 deletions src/test/libraryTest/parser/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,22 @@ describe("Parser.AbridgedNode", () => {
];
assertAbridgeNodes(text, expected);
});

it(`[#"a""" = 1]`, () => {
const text: string = `[#"a""" = 1]`;
const expected: ReadonlyArray<AbridgedNode> = [
[Language.Ast.NodeKind.RecordExpression, undefined],
[Language.Ast.NodeKind.Constant, 0],
[Language.Ast.NodeKind.ArrayWrapper, 1],
[Language.Ast.NodeKind.Csv, 0],
[Language.Ast.NodeKind.GeneralizedIdentifierPairedExpression, 0],
[Language.Ast.NodeKind.GeneralizedIdentifier, 0],
[Language.Ast.NodeKind.Constant, 1],
[Language.Ast.NodeKind.LiteralExpression, 2],
[Language.Ast.NodeKind.Constant, 2],
];
assertAbridgeNodes(text, expected);
});
});

it(`Ast.NodeKind.GeneralizedIdentifierPairedAnyLiteral`, () => {
Expand Down Expand Up @@ -850,14 +866,16 @@ describe("Parser.AbridgedNode", () => {

// Ast.NodeKind.Identifier covered by many

it(`${Language.Ast.NodeKind.IdentifierExpression}`, () => {
const text: string = `@foo`;
const expected: ReadonlyArray<AbridgedNode> = [
[Language.Ast.NodeKind.IdentifierExpression, undefined],
[Language.Ast.NodeKind.Constant, 0],
[Language.Ast.NodeKind.Identifier, 1],
];
assertAbridgeNodes(text, expected);
describe(`${Language.Ast.NodeKind.IdentifierExpression}`, () => {
it(`@foo`, () => {
const text: string = `@foo`;
const expected: ReadonlyArray<AbridgedNode> = [
[Language.Ast.NodeKind.IdentifierExpression, undefined],
[Language.Ast.NodeKind.Constant, 0],
[Language.Ast.NodeKind.Identifier, 1],
];
assertAbridgeNodes(text, expected);
});
});

it(`${Language.Ast.NodeKind.IdentifierPairedExpression}`, () => {
Expand Down