-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
WIP: Feature/calendar unit test #487
Open
kaiyuan01
wants to merge
12
commits into
wenyan-lang:master
Choose a base branch
from
kaiyuan01:feature/calendar-test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a4154fb
Create nodejs.yml
kaiyuan01 ce1ed87
Merge remote-tracking branch 'upstream/master'
kaiyuan01 8ac47c2
WIP: add unit test for calendar
kaiyuan01 d537d2b
Chaged test cases so they can stand up the time :-) A few functions d…
kaiyuan01 c5ea2b8
added test case for function '言百內數'
kaiyuan01 ab5dae3
restructured calendar test: Going forward, one file per unit test
kaiyuan01 9b613c1
added four more functions to calendar unit test suite
kaiyuan01 7595c1c
added four more functions to calendar unit test suite
kaiyuan01 4b7c90e
trivial: fixed typo
kaiyuan01 7831a8e
trivial: clean up/re-format output messages
kaiyuan01 2cb9c6f
completed all test cases fr calendar
kaiyuan01 71d47e2
clean up
kaiyuan01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Node CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [8.x, 10.x, 12.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: npm install, build, and test | ||
run: | | ||
npm ci | ||
npm run build --if-present | ||
npm test | ||
env: | ||
CI: true |
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,4 @@ | ||
吾嘗觀「「曆法」」之書。方悟「言彼之時刻」之義。 | ||
|
||
注曰「「言彼之時刻。同Javascript之new Date(x * 1000).toTimeString(), in Chinese calendar也。」」 | ||
吾有二言。曰「「施「言彼之時刻」於四千七百一十四? 」」。施「言彼之時刻」於四千七百一十四。書之。 |
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,4 @@ | ||
吾嘗觀「「曆法」」之書。方悟「言彼之年月日」之義。 | ||
|
||
批曰。「「今有一術。名之曰「言彼之年月日」。欲行是術。必先得一數。曰「時」。」」。 | ||
吾有二言。曰「「施「言彼之年月日」於四千七百一十四 (「時」)?」」。施「言彼之年月日」於四千七百一十四。書之。 |
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,4 @@ | ||
吾嘗觀「「曆法」」之書。方悟「言彼之日時」之義。 | ||
|
||
批曰。「「欲行是術。必先得一數。曰「時」」」。 | ||
吾有二言。曰「「施「言彼之日時」於四千七百一十四? (「時」)」」。施「言彼之日時」於四千七百一十四。書之。 |
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,3 @@ | ||
吾嘗觀「「曆法」」之書。方悟「彼年何年號」之義。 | ||
|
||
吾有二言。曰「「施「彼年何年號」於四千七百一十四? 」」。施「彼年何年號」於四千七百一十四。書之。 |
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,27 @@ | ||
吾嘗觀「「曆法」」之書。方悟「彼月積何月」「彼月何月」「彼年積何年」「彼年何干支」「今年何年」「言今之日時」「今何紀元時」「今年積何年」「言序數」「言百內數」「言年月日」「彼刻何刻」「彼年何年」「彼日何干支」之義。 | ||
|
||
批曰。「「「今年何干支」「今年積何年」。吾有二言。曰「「今年何干支?」」。施「今年何干支」。書之。」」。 | ||
批曰。「「吾有二言。曰「「今年積何年?」」。施「今年積何年」。書之。」」。 | ||
|
||
批曰。「「吾有一數。曰十。名之曰「甲」。」」。 | ||
批曰。「「吾有二言。曰「「施「言序數」於「甲/十」?」」。 施「言序數」於十。書之。 | ||
吾有二言。曰「「施「言年月日」於「甲/十」?」」。 施「言年月日」於十。書之。 | ||
施「言今之日時」。書之。 | ||
施「今年何年」。書之。 | ||
|
||
|
||
」」。 | ||
|
||
吾有二言。曰「「施「彼年何年」於四千七百一十六?」」。施「彼年何年」於四千七百一十六。書之。 | ||
吾有二言。曰「「施「彼刻何刻」於四千七百一十?」」。施「彼刻何刻」於四千七百一十。書之。 | ||
吾有二言。曰「「施「彼日何干支」於四千七百一十四?」」。施「彼日何干支」於四千七百一十四。書之。 | ||
吾有二言。曰「「施「彼年何干支」於四千七百一十四?」」。施「彼年何干支」於四千七百一十四。書之。 | ||
|
||
吾有一列。名之曰「天地」。 | ||
充「天地」以「彼年積何年」。以「彼月何月」。以「彼月積何月」。「彼日何日」。「彼日何干支」。「彼日積何日」。「彼時何時」。 | ||
「彼時何小時」。「彼刻何刻」。「彼分何分」。「彼秒何秒」。 | ||
|
||
凡「天地」中之「功夫」。 | ||
吾有四言。曰「「施「」」。曰「功夫」。曰「「」於四千七百一十四?」」。施「功夫」於四千七百一十四。書之。 | ||
云云。 | ||
|
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,117 @@ | ||
var fs = require("fs-extra"); | ||
var path = require("path"); | ||
var utils = require("../tools/utils"); | ||
var execSync = require("child_process").execSync; | ||
var { expect } = require("chai"); | ||
var { compile, evalCompiled } = require("../src/parser"); | ||
|
||
var lib = utils.loadlib(); | ||
const exampleDir = path.resolve(__dirname, "../examples/calendar"); | ||
const outputDir = path.resolve(__dirname, "../test/temp/examples/calendar"); | ||
const python = getPythonExecutable(); | ||
|
||
const ignoreExamples = [ | ||
"divination", // contains randomness | ||
"import", // prints current time | ||
"tree2", // DOM manipulate | ||
"tree" // DOM manipulate | ||
]; | ||
|
||
function getPythonExecutable() { | ||
try { | ||
const output = execSync(`python3 -V`).toString(); | ||
if (output && +output[7] === 3) return "python3"; | ||
} catch (e) {} | ||
try { | ||
const output = execSync(`python -V`).toString(); | ||
if (output && +output[7] === 3) return "python"; | ||
} catch (e) {} | ||
return undefined; | ||
} | ||
|
||
function readOtherExample(x) { | ||
console.log("Entering function readOtherExample: x = " + x); | ||
return fs | ||
.readFileSync( | ||
path.resolve(__dirname, "../examples/.calendar" + x + ".wy"), | ||
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. The problem seems to from this. - path.resolve(__dirname, "../examples/.calendar" + x + ".wy"),
+ path.resolve(__dirname, "../examples/calendar", x + ".wy"), |
||
"utf-8" | ||
) | ||
.toString(); | ||
} | ||
|
||
function runExample(lang, name, options = {}) { | ||
//console.log("Entering function runExample: name = " + name); | ||
var code = fs | ||
.readFileSync(path.join(exampleDir, name + ".wy"), "utf-8") | ||
.toString(); | ||
|
||
var compiled = compile(lang, code, { | ||
logCallback: () => {}, | ||
reader: readOtherExample, | ||
lib: lib, | ||
...options | ||
}); | ||
|
||
if (ignoreExamples.includes(name)) return; | ||
|
||
let output = ""; | ||
|
||
evalCompiled(compiled, { | ||
scoped: true, | ||
lang, | ||
output: (...args) => (output += args.join(" ") + "\n"), | ||
...options | ||
}); | ||
|
||
console.log("Output from " + name + ".wy script: \n" + output); | ||
expect(output).to.matchSnapshot(); | ||
/* | ||
expect(output).to.equal( | ||
"施「言彼之日時」於四千七百一十四? (「時」) 西元一九六九年己酉年十一月二十四日辛巳日丑初一刻三分三十四秒\n" + | ||
"施「彼年何年」於四千七百一十六? 一千九百六十九\n施「彼刻何刻」於四千七百一十? 一\n" + | ||
"施「彼日何干支」於四千七百一十四? 一十八\n" | ||
|
||
); | ||
*/ | ||
} | ||
|
||
function runCal(lang, options) { | ||
var files = fs.readdirSync(exampleDir).filter(x => x.endsWith(".wy")); | ||
//console.log("Files to be tested: " + files); | ||
|
||
//var files = fs.readdirSync(exampleDir).filter("import.wy"); | ||
for (const file of files) { | ||
//console.log("File being processed: " + file); | ||
|
||
const filename = file.split(".")[0]; | ||
it(filename, () => runExample(lang, filename, options)); | ||
} | ||
} | ||
|
||
describe("===== wen-yan calendar unit test suite =====", () => { | ||
before(() => { | ||
fs.removeSync(outputDir); | ||
fs.ensureDirSync(outputDir); | ||
}); | ||
|
||
describe("javascript", () => { | ||
runCal("js"); | ||
}); | ||
|
||
describe("romanizeIdentifiers", () => { | ||
runCal("js", { romanizeIdentifiers: true }); | ||
}); | ||
|
||
/* FIXME: there are errors for python compiler | ||
if (python) { | ||
describe("python", () => { | ||
runAll("py"); | ||
}) | ||
} | ||
else { | ||
describe("python", () => { | ||
it("skipped", ()=>{}) | ||
}) | ||
} | ||
*/ | ||
}); | ||
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. You should also run |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The
npm t
should run all the tests. This extra action config seems to be not necessary.