-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make sort sensitivity opt-in and configurable #41
Changes from 3 commits
c9e0514
aa85c6f
0e68a1b
6b72ec6
53755f4
572f83b
3f38fd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,11 @@ import { PostProcessorInterface } from '../../src/post-processors/post-processor | |
import { SortByKeyPostProcessor } from '../../src/post-processors/sort-by-key.post-processor.js'; | ||
import { TranslationCollection } from '../../src/utils/translation.collection.js'; | ||
|
||
describe('SortByKeyPostProcessor', () => { | ||
describe('SortByKeyPostProcessor - base sensitivity should sort lowercase and uppercase equally', () => { | ||
let processor: PostProcessorInterface; | ||
|
||
beforeEach(() => { | ||
processor = new SortByKeyPostProcessor(); | ||
processor = new SortByKeyPostProcessor('base'); | ||
}); | ||
|
||
it('should sort keys alphanumerically', () => { | ||
|
@@ -27,6 +27,15 @@ describe('SortByKeyPostProcessor', () => { | |
b: {value: 'another value', sourceFiles: []}, | ||
z: {value: 'last value', sourceFiles: []} | ||
}); | ||
|
||
expect(Object.keys(processor.process(collection, extracted, existing).values)).to.deep.equal( | ||
Object.keys({ | ||
'9': {value: 'a numeric key', sourceFiles: [] }, | ||
a: {value: 'a value', sourceFiles: [] }, | ||
b: {value: 'another value', sourceFiles: [] }, | ||
z: {value: 'last value', sourceFiles: [] } | ||
}) | ||
); | ||
}); | ||
|
||
it('should perform case insensitive sorting', () => { | ||
|
@@ -47,6 +56,96 @@ describe('SortByKeyPostProcessor', () => { | |
g: { value: 'letter g', sourceFiles: [] } | ||
}); | ||
|
||
expect(processor.process(collection, new TranslationCollection(), new TranslationCollection()).values).to.deep.equal({ | ||
c: {value: 'letter c', sourceFiles: [] }, | ||
j: {value: 'letter j', sourceFiles: [] }, | ||
b: {value: 'letter b', sourceFiles: [] }, | ||
a: {value: 'letter a', sourceFiles: [] }, | ||
h: {value: 'letter h', sourceFiles: [] }, | ||
B: {value: 'letter B', sourceFiles: [] }, | ||
H: {value: 'letter H', sourceFiles: [] }, | ||
i: {value: 'letter i', sourceFiles: [] }, | ||
C: {value: 'letter C', sourceFiles: [] }, | ||
e: {value: 'letter e', sourceFiles: [] }, | ||
f: {value: 'letter f', sourceFiles: [] }, | ||
d: {value: 'letter d', sourceFiles: [] }, | ||
A: {value: 'letter A', sourceFiles: [] }, | ||
g: {value: 'letter g', sourceFiles: [] } | ||
}); | ||
|
||
expect(Object.keys(processor.process(collection, new TranslationCollection(), new TranslationCollection()).values)).to.deep.equal( | ||
Object.keys({ | ||
a: {value: 'letter a', sourceFiles: [] }, | ||
A: {value: 'letter A', sourceFiles: [] }, | ||
b: {value: 'letter b', sourceFiles: [] }, | ||
B: {value: 'letter B', sourceFiles: [] }, | ||
c: {value: 'letter c', sourceFiles: [] }, | ||
C: {value: 'letter C', sourceFiles: [] }, | ||
d: {value: 'letter d', sourceFiles: [] }, | ||
e: {value: 'letter e', sourceFiles: [] }, | ||
f: {value: 'letter f', sourceFiles: [] }, | ||
g: {value: 'letter g', sourceFiles: [] }, | ||
h: {value: 'letter h', sourceFiles: [] }, | ||
H: {value: 'letter H', sourceFiles: [] }, | ||
i: {value: 'letter i', sourceFiles: [] }, | ||
j: {value: 'letter j', sourceFiles: [] } | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
describe('SortByKeyPostProcessor - undefined sort sensitivity should sort lowercase and uppercase separatly', () => { | ||
let processor: PostProcessorInterface; | ||
|
||
beforeEach(() => { | ||
processor = new SortByKeyPostProcessor(undefined); | ||
}); | ||
|
||
it('should sort keys alphanumerically', () => { | ||
const collection = new TranslationCollection({ | ||
z: {value: 'last value', sourceFiles: [] }, | ||
a: {value: 'a value', sourceFiles: [] }, | ||
'9': {value: 'a numeric key', sourceFiles: [] }, | ||
b: {value: 'another value', sourceFiles: [] } | ||
}); | ||
const extracted = new TranslationCollection(); | ||
const existing = new TranslationCollection(); | ||
|
||
expect(processor.process(collection, extracted, existing).values).to.deep.equal({ | ||
'9': {value: 'a numeric key', sourceFiles: [] }, | ||
a: {value: 'a value', sourceFiles: [] }, | ||
b: {value: 'another value', sourceFiles: [] }, | ||
z: {value: 'last value', sourceFiles: [] } | ||
}); | ||
|
||
expect(Object.keys(processor.process(collection, extracted, existing).values)).to.deep.equal( | ||
Object.keys({ | ||
'9': {value: 'a numeric key', sourceFiles: [] }, | ||
a: {value: 'a value', sourceFiles: [] }, | ||
b: {value: 'another value', sourceFiles: [] }, | ||
z: {value: 'last value', sourceFiles: [] } | ||
}) | ||
); | ||
}); | ||
|
||
it('should perform case sensitive sorting', () => { | ||
const collection = new TranslationCollection({ | ||
c: {value: 'letter c', sourceFiles: [] }, | ||
j: {value: 'letter j', sourceFiles: [] }, | ||
b: {value: 'letter b', sourceFiles: [] }, | ||
a: {value: 'letter a', sourceFiles: [] }, | ||
h: {value: 'letter h', sourceFiles: [] }, | ||
B: {value: 'letter B', sourceFiles: [] }, | ||
H: {value: 'letter H', sourceFiles: [] }, | ||
i: {value: 'letter i', sourceFiles: [] }, | ||
C: {value: 'letter C', sourceFiles: [] }, | ||
e: {value: 'letter e', sourceFiles: [] }, | ||
f: {value: 'letter f', sourceFiles: [] }, | ||
d: {value: 'letter d', sourceFiles: [] }, | ||
A: {value: 'letter A', sourceFiles: [] }, | ||
g: {value: 'letter g', sourceFiles: [] } | ||
}); | ||
|
||
expect(processor.process(collection, new TranslationCollection(), new TranslationCollection()).values).to.deep.equal({ | ||
A: { value: 'letter A', sourceFiles: [] }, | ||
a: { value: 'letter a', sourceFiles: [] }, | ||
|
@@ -63,5 +162,24 @@ describe('SortByKeyPostProcessor', () => { | |
i: { value: 'letter i', sourceFiles: [] }, | ||
j: { value: 'letter j', sourceFiles: [] } | ||
}); | ||
|
||
expect(Object.keys(processor.process(collection, new TranslationCollection(), new TranslationCollection()).values)).to.deep.equal( | ||
Object.keys({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand what this assertion is testing beyond what the test above it is testing? Can you clarify this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to my findings, the I modified the assertion a bit and added some comments to make this more clear Additionally, some tests were added to have at least one assertion per sort-sensitivity option |
||
A: {value: 'letter A', sourceFiles: [] }, | ||
B: {value: 'letter B', sourceFiles: [] }, | ||
C: {value: 'letter C', sourceFiles: [] }, | ||
H: {value: 'letter H', sourceFiles: [] }, | ||
a: {value: 'letter a', sourceFiles: [] }, | ||
b: {value: 'letter b', sourceFiles: [] }, | ||
c: {value: 'letter c', sourceFiles: [] }, | ||
d: {value: 'letter d', sourceFiles: [] }, | ||
e: {value: 'letter e', sourceFiles: [] }, | ||
f: {value: 'letter f', sourceFiles: [] }, | ||
g: {value: 'letter g', sourceFiles: [] }, | ||
h: {value: 'letter h', sourceFiles: [] }, | ||
i: {value: 'letter i', sourceFiles: [] }, | ||
j: {value: 'letter j', sourceFiles: [] } | ||
}) | ||
); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to add a dedicated section to the readme about sorting now. If I understand correctly, the
-ss
flag only has an effect in combination with the-s
flag right? That should be noted.Also this section can explain how strings will be sorted without the
-ss
flag, as well as what the different options are and what effect they have on the sort order.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Limitations for the
-ss
flag have been added, as well as a separate section in the README