Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
Add smart case comparison to autocompletion. Fixes #487.
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad-shatskyi committed Jun 9, 2016
1 parent e58dda4 commit 91d97e6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ function getProgress(input: string, expected: string) {
return Progress.OnStart;
}

if (input.startsWith(expected)) {
const normalizedExpected = input === input.toLowerCase() ? expected.toLowerCase() : expected;

if (input.startsWith(normalizedExpected)) {
return Progress.Finished;
}

if (expected.length <= input.length) {
if (normalizedExpected.length <= input.length) {
return Progress.Failed;
}

if (expected.startsWith(input)) {
if (normalizedExpected.startsWith(input)) {
return Progress.InProgress;
}

Expand Down
19 changes: 19 additions & 0 deletions test/parser_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,23 @@ describe("parser", () => {
expect(suggestionDisplayValues(results)).to.eql(["git"]);
});
});

describe("case sensitivity", () => {
describe("when user types only lowercase letters", () => {
it("is case insensitive", async() => {
const results = await parse(sequence(string("./Downloads"), string("/mine")), "./down");

expect(results.length).to.equal(1);
expect(suggestionDisplayValues(results)).to.eql(["./Downloads"]);
});
});

describe("when user input contains uppercase letters", () => {
it("is case sensitive", async() => {
const results = await parse(sequence(string("./documents"), string("/mine")), "./Do");

expect(results.length).to.equal(0);
});
});
});
});

0 comments on commit 91d97e6

Please sign in to comment.