Skip to content

Commit 053ddf6

Browse files
authored
Merge pull request #286 from shivam71/Localisation_Tests
Added tests for localisation
2 parents c6ecb29 + 033de58 commit 053ddf6

File tree

5 files changed

+399
-1
lines changed

5 files changed

+399
-1
lines changed

vscode/src/test/constants.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,8 @@ public class App {
238238
System.out.println("Hello, yourProject!");
239239
}
240240
}
241-
`
241+
`;
242+
export const EXTENSION_NAME = "oracle.oracle-java";
243+
export const DEFAULT_BUNDLE_FILE_NAME = "bundle.l10n.en.json";
244+
export const SUPPORTED_LANGUAGES = new Set(["ja", "zh-cn"]);
245+
export const DEFAULT_PACKAGE_FILE_NAME = "package.nls.json";
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates.
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
/* This file has been modified for Oracle Java SE extension */
23+
24+
import * as assert from 'assert';
25+
import * as fs from 'fs';
26+
import * as path from 'path';
27+
import * as vscode from 'vscode';
28+
29+
import { extensions, window } from 'vscode';
30+
import { DEFAULT_BUNDLE_FILE_NAME, DEFAULT_PACKAGE_FILE_NAME, EXTENSION_NAME, SUPPORTED_LANGUAGES } from '../../constants';
31+
import { checkCommandsLocalisation, checkConfigurationLocalisation, checkDebuggersLocalisation, checkL10nUsageInFiles, checkViewsLocalisation, getKeysFromJSON, matchKeys, matchValuesTemplate } from '../../testutils';
32+
33+
34+
suite("Extension localisation tests", function () {
35+
window.showInformationMessage("Starting Localisation tests");
36+
// Check the consistency of the keys and value templates across the bundle files for the supported languages
37+
test("Consistency of keys across bundle.l10n.lang.json files for supported languages", async () => {
38+
const extension = extensions.getExtension(EXTENSION_NAME);
39+
assert(extension);
40+
const enBundlePath = path.join(extension.extensionPath, "l10n", DEFAULT_BUNDLE_FILE_NAME);
41+
assert.ok(fs.existsSync(enBundlePath), `${DEFAULT_BUNDLE_FILE_NAME} doesn't exists`);
42+
for (const lang of SUPPORTED_LANGUAGES) {
43+
const langBundlePath = path.join(extension.extensionPath, "l10n", `bundle.l10n.${lang}.json`);
44+
assert.ok(fs.existsSync(langBundlePath), `bundle.l10n.${lang}.json doesn't exists`);
45+
assert.ok(matchKeys(enBundlePath, langBundlePath), `Keys of ${DEFAULT_BUNDLE_FILE_NAME} and bundle.l10n.${lang}.json don't match`);
46+
assert.ok(matchValuesTemplate(enBundlePath, langBundlePath), `Value templates don't match for of the keys of ${DEFAULT_BUNDLE_FILE_NAME} and bundle.l10n.${lang}.json `);
47+
}
48+
}).timeout(10000);
49+
50+
test("Consistency of keys across package.nls.lang.json files for supported languages", async () => {
51+
const extension = extensions.getExtension(EXTENSION_NAME);
52+
assert(extension);
53+
const enPackagePath = path.join(extension.extensionPath, DEFAULT_PACKAGE_FILE_NAME);
54+
assert.ok(fs.existsSync(enPackagePath), `${DEFAULT_PACKAGE_FILE_NAME} doesn't exists`);
55+
for (const lang of SUPPORTED_LANGUAGES) {
56+
const langPackagePath = path.join(extension.extensionPath, `package.nls.${lang}.json`);
57+
assert.ok(fs.existsSync(langPackagePath), `package.nls.${lang}.json doesn't exists`);
58+
assert.ok(matchKeys(enPackagePath, langPackagePath), `Keys of ${DEFAULT_PACKAGE_FILE_NAME} and package.nls.${lang}.json don't match`);
59+
}
60+
}).timeout(10000);
61+
62+
// Check localisable fields being appropriately localised for the contributes defined in package.json
63+
test("Localisable fields in package.json localised properly ", async () => {
64+
const extension = extensions.getExtension(EXTENSION_NAME);
65+
assert(extension);
66+
const packagePath = path.join(extension.extensionPath, "package.json");
67+
assert.ok(fs.existsSync(packagePath), "package.json doesn't exists");
68+
const enPackagePath = path.join(extension.extensionPath, DEFAULT_PACKAGE_FILE_NAME);
69+
assert.ok(fs.existsSync(enPackagePath), `${DEFAULT_PACKAGE_FILE_NAME} doesn't exists`);
70+
const validKeys: Set<string> = getKeysFromJSON(enPackagePath);
71+
const packageObj = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
72+
const contributes = packageObj.contributes
73+
assert.ok(checkCommandsLocalisation(contributes.commands, validKeys), "Error some commands not localized");
74+
assert.ok(checkViewsLocalisation(contributes.views, validKeys), "Error some views is not localized");
75+
assert.ok(checkDebuggersLocalisation(contributes.debuggers, validKeys), "Error some debugger labels not localized");
76+
assert.ok(checkConfigurationLocalisation(contributes.configuration, validKeys), "Error some configuration labels not localized");
77+
}).timeout(10000);
78+
79+
80+
// Check if l10n.value is called with a valid key and the placeholder map has all the keys as required in the string template
81+
test("Proper usage of l10n.value for localisation in the ts/js code files", async () => {
82+
const ignoredDirEntriesNames = new Set(["test"]); // Names of folders,files( .js only),subfolders within the out directory which are not to be checked
83+
const extension = vscode.extensions.getExtension(EXTENSION_NAME);
84+
assert(extension, "extension not found");
85+
const enBundlePath = path.join(extension.extensionPath, "l10n", DEFAULT_BUNDLE_FILE_NAME);
86+
assert(enBundlePath, `${DEFAULT_BUNDLE_FILE_NAME} not found`);
87+
const validKeyValues = JSON.parse(fs.readFileSync(enBundlePath, 'utf8'));
88+
assert(checkL10nUsageInFiles(path.join(extension.extensionPath, "out"), ignoredDirEntriesNames, validKeyValues) === 0, "Some files have invalid localisation keys used. Check the logs or error messages");
89+
}).timeout(10000);
90+
91+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
/*
3+
* Copyright (c) 2023, Oracle and/or its affiliates.
4+
*
5+
* Licensed to the Apache Software Foundation (ASF) under one
6+
* or more contributor license agreements. See the NOTICE file
7+
* distributed with this work for additional information
8+
* regarding copyright ownership. The ASF licenses this file
9+
* to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance
11+
* with the License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing,
16+
* software distributed under the License is distributed on an
17+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18+
* KIND, either express or implied. See the License for the
19+
* specific language governing permissions and limitations
20+
* under the License.
21+
*/
22+
import { runTestSuite } from '../../testutils';
23+
24+
export function run(): Promise<void> {
25+
return runTestSuite(__dirname);
26+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
/*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*/
20+
export function empty(): any {
21+
}

0 commit comments

Comments
 (0)