Move things out of src
parent
dd31fa8404
commit
91bdf113d0
|
@ -34,4 +34,4 @@ jobs:
|
|||
run: |
|
||||
ls
|
||||
ls ..
|
||||
v src/whisker_cli
|
||||
v whisker_cli
|
||||
|
|
|
@ -19,4 +19,4 @@ bin/
|
|||
scratch
|
||||
|
||||
# Ignore generated spec duplicate
|
||||
src/spec/gen
|
||||
spec/gen
|
||||
|
|
|
@ -195,10 +195,10 @@ Output
|
|||
```
|
||||
|
||||
All the examples shown here are tested in CI in
|
||||
the [readme_test.v](src/spec/readme_test.v) file.
|
||||
the [readme_test.v](spec/readme_test.v) file.
|
||||
|
||||
For the full specification, refer to the unit tests and test cases in
|
||||
the [`spec`](src/spec) directory.
|
||||
the [`spec`](spec) directory.
|
||||
|
||||
## Installation
|
||||
|
||||
|
@ -259,9 +259,9 @@ _whisker_ may also be used as a standalone command-line program to process
|
|||
template files. It does not support direct template string input for the sake of
|
||||
simplicity.
|
||||
|
||||
Build `src/whisker_cli` and run `whisker --help` for usage instructions.
|
||||
Build `whisker_cli` and run `whisker --help` for usage instructions.
|
||||
|
||||
Check [whisker_cli_test.v](src/whisker_cli/whisker_cli_test.v) for a concrete
|
||||
Check [whisker_cli_test.v](whisker_cli/whisker_cli_test.v) for a concrete
|
||||
demonstration.
|
||||
|
||||
## License
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
module main
|
||||
|
||||
import whisker
|
||||
import os
|
||||
import net.html
|
||||
|
||||
fn test_html_template_files() {
|
||||
partials := {
|
||||
'footer': 'spec/template_files/html/footer.wskr.html'
|
||||
'header': 'spec/template_files/html/header.wskr.html'
|
||||
'head': 'spec/template_files/html/head.wskr.html'
|
||||
'main': 'spec/template_files/html/main.wskr.html'
|
||||
}
|
||||
mut template := whisker.load_template(
|
||||
input: 'spec/template_files/html/base.wskr.html'
|
||||
partials: partials
|
||||
)!
|
||||
cases := os.ls('spec/template_files/html/cases')!
|
||||
|
||||
for case in cases {
|
||||
data := whisker.from_json(os.read_file('spec/template_files/html/cases/${case}/data.wskr.json')!)!
|
||||
raw_result := template.run(data)!
|
||||
result_html := html.parse(raw_result)
|
||||
|
||||
raw_expected := os.read_file('spec/template_files/html/cases/${case}/expected.html')!
|
||||
expected_html := html.parse(raw_expected)
|
||||
|
||||
assert result_html.get_root().str() == expected_html.get_root().str(), 'Assertion failed for case ${case}'
|
||||
}
|
||||
}
|
|
@ -49,17 +49,17 @@ fn test_simple_json_api() {
|
|||
|
||||
fn test_json_template_files() {
|
||||
partials := {
|
||||
'article': 'src/spec/template_files/json/Article.partial.wskr.json'
|
||||
'author': 'src/spec/template_files/json/Author.partial.wskr.json'
|
||||
'article': 'spec/template_files/json/Article.partial.wskr.json'
|
||||
'author': 'spec/template_files/json/Author.partial.wskr.json'
|
||||
}
|
||||
input := 'src/spec/template_files/json/List of Articles.wskr.json'
|
||||
input := 'spec/template_files/json/List of Articles.wskr.json'
|
||||
mut template := whisker.load_template(input: input, partials: partials)!
|
||||
|
||||
data := whisker.from_json(os.read_file('src/spec/template_files/json/Articles.data.wskr.json')!)!
|
||||
data := whisker.from_json(os.read_file('spec/template_files/json/Articles.data.wskr.json')!)!
|
||||
raw_output_string := template.run(data)!
|
||||
pretty_output_string := json2.raw_decode(raw_output_string)!.prettify_json_str()
|
||||
|
||||
raw_expected_string := os.read_file('src/spec/template_files/json/List of Articles.json')!
|
||||
raw_expected_string := os.read_file('spec/template_files/json/List of Articles.json')!
|
||||
pretty_expected_string := json2.raw_decode(raw_expected_string)!.prettify_json_str()
|
||||
|
||||
// dump(pretty_output_string)
|
|
@ -30,25 +30,25 @@ fn test_full_spec() {
|
|||
}
|
||||
|
||||
fn generate_json_files() ! {
|
||||
os.mkdir('src/spec/gen') or {}
|
||||
os.mkdir('spec/gen') or {}
|
||||
|
||||
for suite in spec_test_suites {
|
||||
for test in suite.tests {
|
||||
json_string := json2.encode_pretty(test.data)
|
||||
|
||||
os.mkdir('src/spec/gen/${suite.name}') or {}
|
||||
os.write_file('src/spec/gen/${suite.name}/${test.name}.wskr.json', json_string)!
|
||||
os.mkdir('spec/gen/${suite.name}') or {}
|
||||
os.write_file('spec/gen/${suite.name}/${test.name}.wskr.json', json_string)!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn test_exported_files() ! {
|
||||
if !os.exists('src/spec/gen') {
|
||||
if !os.exists('spec/gen') {
|
||||
generate_json_files()!
|
||||
}
|
||||
for suite in spec_test_suites {
|
||||
for test in suite.tests {
|
||||
json_content := os.read_file('src/spec/gen/${suite.name}/${test.name}.wskr.json')!
|
||||
json_content := os.read_file('spec/gen/${suite.name}/${test.name}.wskr.json')!
|
||||
|
||||
decoded_data := whisker.from_json(json_content)!
|
||||
assert decoded_data == test.data
|
|
@ -1,30 +0,0 @@
|
|||
module main
|
||||
|
||||
import whisker
|
||||
import os
|
||||
import net.html
|
||||
|
||||
fn test_html_template_files() {
|
||||
partials := {
|
||||
'footer': 'src/spec/template_files/html/footer.wskr.html'
|
||||
'header': 'src/spec/template_files/html/header.wskr.html'
|
||||
'head': 'src/spec/template_files/html/head.wskr.html'
|
||||
'main': 'src/spec/template_files/html/main.wskr.html'
|
||||
}
|
||||
mut template := whisker.load_template(
|
||||
input: 'src/spec/template_files/html/base.wskr.html'
|
||||
partials: partials
|
||||
)!
|
||||
cases := os.ls('src/spec/template_files/html/cases')!
|
||||
|
||||
for case in cases {
|
||||
data := whisker.from_json(os.read_file('src/spec/template_files/html/cases/${case}/data.wskr.json')!)!
|
||||
raw_result := template.run(data)!
|
||||
result_html := html.parse(raw_result)
|
||||
|
||||
raw_expected := os.read_file('src/spec/template_files/html/cases/${case}/expected.html')!
|
||||
expected_html := html.parse(raw_expected)
|
||||
|
||||
assert result_html.get_root().str() == expected_html.get_root().str(), 'Assertion failed for case ${case}'
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
module main
|
||||
|
||||
import os
|
||||
import net.html
|
||||
|
||||
fn test_whisker_cli() {
|
||||
cases := os.ls('./src/spec/template_files/html/cases')!
|
||||
for case in cases {
|
||||
result := os.execute_or_panic('${os.quoted_path(@VEXE)} run src/whisker_cli' +
|
||||
' --input ./src/spec/template_files/html/base.wskr.html' +
|
||||
' --data ./src/spec/template_files/html/cases/${case}/data.wskr.json' +
|
||||
' --partials head:./src/spec/template_files/html/head.wskr.html,' +
|
||||
'header:./src/spec/template_files/html/header.wskr.html,' +
|
||||
'main:./src/spec/template_files/html/main.wskr.html,' +
|
||||
'footer:./src/spec/template_files/html/footer.wskr.html')
|
||||
|
||||
result_html := html.parse(result.output).get_root().str()
|
||||
expected_html := html.parse(os.read_file('./src/spec/template_files/html/cases/${case}/expected.html')!).get_root().str()
|
||||
|
||||
assert result_html == expected_html
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
module main
|
||||
|
||||
import os
|
||||
import net.html
|
||||
|
||||
fn test_whisker_cli() {
|
||||
cases := os.ls('spec/template_files/html/cases')!
|
||||
for case in cases {
|
||||
result := os.execute_or_panic('${os.quoted_path(@VEXE)} run whisker_cli' +
|
||||
' --input spec/template_files/html/base.wskr.html' +
|
||||
' --data spec/template_files/html/cases/${case}/data.wskr.json' +
|
||||
' --partials head:spec/template_files/html/head.wskr.html,' +
|
||||
'header:spec/template_files/html/header.wskr.html,' +
|
||||
'main:spec/template_files/html/main.wskr.html,' +
|
||||
'footer:spec/template_files/html/footer.wskr.html')
|
||||
|
||||
result_html := html.parse(result.output).get_root().str()
|
||||
expected_html := html.parse(os.read_file('spec/template_files/html/cases/${case}/expected.html')!).get_root().str()
|
||||
|
||||
assert result_html == expected_html
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue