-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
translate definition file in english
add a test to make sure labels are consistent in both fr and en files, fix some issues in both definition files closes #1135
- Loading branch information
Showing
5 changed files
with
572 additions
and
532 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
packages/transition-backend/file/__tests__/definitions.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import fs from 'fs'; | ||
describe('LaTeX Label Consistency Tests', () => { | ||
// Helper function to extract labels from LaTeX content | ||
function extractLabels(content) { | ||
const labelRegex = /\\label{([^}]+)}/g; | ||
const labels = new Set(); | ||
let match; | ||
|
||
while ((match = labelRegex.exec(content)) !== null) { | ||
labels.add(match[1]); | ||
} | ||
|
||
return labels; | ||
} | ||
|
||
// Read both files before all tests | ||
let enContent; | ||
let frContent; | ||
let enLabels; | ||
let frLabels; | ||
|
||
beforeAll(() => { | ||
enContent = fs.readFileSync('file/definitions/definitions-en.tex', 'utf8'); | ||
frContent = fs.readFileSync('file/definitions/definitions-fr.tex', 'utf8'); | ||
enLabels = extractLabels(enContent); | ||
frLabels = extractLabels(frContent); | ||
}); | ||
|
||
test('all English labels exist in French file', () => { | ||
const missingInFr = [...enLabels].filter((label) => !frLabels.has(label)); | ||
expect(missingInFr).toEqual([]); | ||
}); | ||
|
||
test('all French labels exist in English file', () => { | ||
const missingInEn = [...frLabels].filter((label) => !enLabels.has(label)); | ||
expect(missingInEn).toEqual([]); | ||
}); | ||
|
||
test('both files have the same number of labels', () => { | ||
expect(enLabels.size).toBe(frLabels.size); | ||
}); | ||
|
||
test('labels appear in the same order in both files', () => { | ||
const enLabelArray = [...enLabels]; | ||
const frLabelArray = [...frLabels]; | ||
|
||
expect(enLabelArray).toEqual(frLabelArray); | ||
}); | ||
|
||
test('no duplicate labels in English file', () => { | ||
const duplicates = new Set(); | ||
const seen = new Set(); | ||
const labelRegex = /\\label{([^}]+)}/g; | ||
let match; | ||
|
||
while ((match = labelRegex.exec(enContent)) !== null) { | ||
const label = match[1]; | ||
if (seen.has(label)) { | ||
duplicates.add(label); | ||
} | ||
seen.add(label); | ||
} | ||
|
||
expect([...duplicates]).toEqual([]); | ||
}); | ||
|
||
test('no duplicate labels in French file', () => { | ||
const duplicates = new Set(); | ||
const seen = new Set(); | ||
const labelRegex = /\\label{([^}]+)}/g; | ||
let match; | ||
|
||
while ((match = labelRegex.exec(frContent)) !== null) { | ||
const label = match[1]; | ||
if (seen.has(label)) { | ||
duplicates.add(label); | ||
} | ||
seen.add(label); | ||
} | ||
|
||
expect([...duplicates]).toEqual([]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.