Skip to content

Commit

Permalink
feat(developer): unit tests for kmc-generate
Browse files Browse the repository at this point in the history
Note: these are more e2e than unit tests. It may be difficult to convert
them into solid unit tests due to the way that kmc-generate works based
on templates.
  • Loading branch information
mcdurdin committed Jun 25, 2024
1 parent 125cfe6 commit a45abe4
Show file tree
Hide file tree
Showing 39 changed files with 860 additions and 29 deletions.
4 changes: 4 additions & 0 deletions developer/src/kmc-generate/src/abstract-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,9 @@ export class AbstractGenerator {
public readonly unitTestEndpoints = {
targetPath: this.targetPath
}
/**
* @internal
*/
public get test_tokenMap() { return this._tokenMap; }
}

18 changes: 16 additions & 2 deletions developer/src/kmc-generate/src/basic-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export class BasicGenerator extends AbstractGenerator {
}

protected generate(artifacts: GeneratorArtifacts): boolean {


return this.transformAll(artifacts);
}

Expand Down Expand Up @@ -112,4 +110,20 @@ export class BasicGenerator extends AbstractGenerator {

return true;
}

/**
* @internal
* these are exported only for unit tests, do not use
*/
public readonly test_templatePath = () => this.templatePath;
public readonly test_languageTags = () => this.languageTags;

public readonly test_preGenerate = () => this.preGenerate();
public readonly test_generate = (artifacts: GeneratorArtifacts) => this.generate(artifacts);
public readonly test_getLanguageName = (tag: string) => this.getLanguageName(tag);
public readonly test_generateLanguageListForPackage = () => this.generateLanguageListForPackage();
public readonly test_getPlatformDotListForReadme = () => this.getPlatformDotListForReadme();
public readonly test_transformAll = (artifacts: GeneratorArtifacts) => this.transformAll(artifacts);
public readonly test_transform = (sourceFile: string, destFile: string, artifacts: GeneratorArtifacts) =>
this.transform(sourceFile, destFile, artifacts);
}
3 changes: 2 additions & 1 deletion developer/src/kmc-generate/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* c8 ignore start */
export { AbstractGenerator, GeneratorOptions } from "./abstract-generator.js";
export { KeymanKeyboardGenerator } from "./keyman-keyboard-generator.js";
export { LexicalModelGenerator } from "./lexical-model-generator.js";
export { LdmlKeyboardGenerator } from "./ldml-keyboard-generator.js";
export { GeneratorMessages } from "./generator-messages.js";
export { GeneratorMessages } from "./generator-messages.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Sample Project Change History
====================

1.0 (2024-04-12)
----------------
* Created by Sample Author
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

© 2024 TheAuthor

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Sample Project keyboard
==============

Description
-----------
# A mighty description

Links
-----
Keyboard Homepage: https://keyman.com/keyboards/sample

Copyright
---------
See [LICENSE.md](LICENSE.md)

Supported Platforms
-------------------
* Windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<KeymanDeveloperProject>
<Options>
<Version>2.0</Version>
<CompilerWarningsAsErrors>True</CompilerWarningsAsErrors>
<CheckFilenameConventions>True</CheckFilenameConventions>
</Options>
</KeymanDeveloperProject>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Sample Project</title>
<style type="text/css">
p { font: 10pt Tahoma; }
h1 { font: bold 16pt Tahoma; color: #4444cc; margin-bottom: 2px }
h2 { font: bold 12pt Tahoma; color: #4444cc; }
</style>
</head>
<body>

<h1>Sample Project</h1>

<p>
# A mighty description
</p>

<p>© TheAuthor</p>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
c keyboard generated from template at 2024-04-12
c with name "Sample Project"
store(&NAME) 'Sample Project'
store(&COPYRIGHT) '© TheAuthor'
store(&VERSION) '10.0'
store(&KEYBOARDVERSION) '1.0'
store(&TARGETS) 'windows'
store(&VISUALKEYBOARD) 'sample.kvks'

begin Unicode > use(main)

group(main) using keys
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Package>
<System>
<KeymanDeveloperVersion>17.0.292.0</KeymanDeveloperVersion>
<FileVersion>7.0</FileVersion>
</System>
<Options>
<ReadMeFile>readme.htm</ReadMeFile>
<LicenseFile>..\LICENSE.md</LicenseFile>
<WelcomeFile>welcome.htm</WelcomeFile>
<FollowKeyboardVersion/>
</Options>
<Info>
<Name URL="">Sample Project</Name>
<Copyright URL="">© TheAuthor</Copyright>
<Author URL="">Sample Author</Author>
<Description URL=""># A mighty description</Description>
</Info>
<Files>
<File>
<Name>..\build\sample.kmx</Name>
<Description></Description>
<CopyLocation>0</CopyLocation>
<FileType>.kmx</FileType>
</File>
<File>
<Name>..\build\sample.kvk</Name>
<Description></Description>
<CopyLocation>0</CopyLocation>
<FileType>.kvk</FileType>
</File>
<File>
<Name>welcome.htm</Name>
<Description></Description>
<CopyLocation>0</CopyLocation>
<FileType>.htm</FileType>
</File>
<File>
<Name>readme.htm</Name>
<Description></Description>
<CopyLocation>0</CopyLocation>
<FileType>.htm</FileType>
</File>
<File>
<Name>..\LICENSE.md</Name>
<Description></Description>
<CopyLocation>0</CopyLocation>
<FileType>.md</FileType>
</File>
</Files>
<Keyboards>
<Keyboard>
<Name>Sample Project</Name>
<ID>sample</ID>
<Version>1.0</Version>
<Languages>
<Language ID="en">en</Language>
</Languages>
</Keyboard>
</Keyboards>
</Package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<visualkeyboard>
<header>
<version>10.0</version>
<kbdname>sample</kbdname>
<flags/>
</header>
</visualkeyboard>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Start Using Sample Project</title>
<style type="text/css">
p { font: 10pt Tahoma; }
h1 { font: bold 16pt Tahoma; color: #4444cc; margin-bottom: 2px }
h2 { font: bold 12pt Tahoma; color: #4444cc; }
</style>
</head>
<body>

<h1>Start Using Sample Project</h1>

<p>
# A mighty description
</p>

<h1>Keyboard Layout</h1>

<!-- Insert Keyboard Layout Images or HTML here -->

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Sample Project Change History
====================

1.0 (2024-04-12)
----------------
* Created by Sample Author
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

© 2024 TheAuthor

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Sample Project keyboard
==============

Description
-----------
# A mighty description

Links
-----
Keyboard Homepage: https://keyman.com/keyboards/sample

Copyright
---------
See [LICENSE.md](LICENSE.md)

Supported Platforms
-------------------
* Windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<KeymanDeveloperProject>
<Options>
<Version>2.0</Version>
<CompilerWarningsAsErrors>True</CompilerWarningsAsErrors>
<CheckFilenameConventions>True</CheckFilenameConventions>
</Options>
</KeymanDeveloperProject>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Sample Project</title>
<style type="text/css">
p { font: 10pt Tahoma; }
h1 { font: bold 16pt Tahoma; color: #4444cc; margin-bottom: 2px }
h2 { font: bold 12pt Tahoma; color: #4444cc; }
</style>
</head>
<body>

<h1>Sample Project</h1>

<p>
# A mighty description
</p>

<p>© TheAuthor</p>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Package>
<System>
<KeymanDeveloperVersion>17.0.292.0</KeymanDeveloperVersion>
<FileVersion>7.0</FileVersion>
</System>
<Options>
<ReadMeFile>readme.htm</ReadMeFile>
<LicenseFile>..\LICENSE.md</LicenseFile>
<WelcomeFile>welcome.htm</WelcomeFile>
<FollowKeyboardVersion/>
</Options>
<Info>
<Name URL="">Sample Project</Name>
<Copyright URL="">© TheAuthor</Copyright>
<Author URL="">Sample Author</Author>
<Description URL=""># A mighty description</Description>
</Info>
<Files>
<File>
<Name>..\build\sample.kmx</Name>
<Description></Description>
<CopyLocation>0</CopyLocation>
<FileType>.kmx</FileType>
</File>
<File>
<Name>..\build\sample.kvk</Name>
<Description></Description>
<CopyLocation>0</CopyLocation>
<FileType>.kvk</FileType>
</File>
<File>
<Name>welcome.htm</Name>
<Description></Description>
<CopyLocation>0</CopyLocation>
<FileType>.htm</FileType>
</File>
<File>
<Name>readme.htm</Name>
<Description></Description>
<CopyLocation>0</CopyLocation>
<FileType>.htm</FileType>
</File>
<File>
<Name>..\LICENSE.md</Name>
<Description></Description>
<CopyLocation>0</CopyLocation>
<FileType>.md</FileType>
</File>
</Files>
<Keyboards>
<Keyboard>
<Name>Sample Project</Name>
<ID>sample</ID>
<Version>1.0</Version>
<Languages>
<Language ID="en">en</Language>
</Languages>
</Keyboard>
</Keyboards>
</Package>
Loading

0 comments on commit a45abe4

Please sign in to comment.