Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Oct 23, 2024
1 parent 081b237 commit 24af8cd
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion v0.5/fastn-p1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub enum SingleError {
// HeaderNotFound,
}

#[test]
// #[test]
fn grammar_test() {
let input = "-- foo bar():";
let lexer = fastn_p1::lexer::Lexer::new(input);
Expand Down
2 changes: 1 addition & 1 deletion v0.5/fastn-p1/src/parser_v3/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl Scanner {
Scanner {
tokens: fastn_p1::Token::lexer(source)
.spanned()
.map(|(r, span)| (dbg!(r.unwrap()), span))
.map(|(r, span)| (dbg!((r, &source[span.clone()])).0.unwrap(), span))
.collect(),
index: 0,
output: fastn_p1::ParseOutput {
Expand Down
8 changes: 6 additions & 2 deletions v0.5/fastn-p1/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ fn test_all() {

fn p1(file: impl AsRef<std::path::Path> + std::fmt::Debug, fix: bool) {
let json = file.as_ref().with_extension("json");
let s = std::fs::read_to_string(&file).unwrap();
let s = {
let mut s = std::fs::read_to_string(&file).unwrap();
s.push('\n');
s
};
println!("testing {file:?}");
let output = fastn_p1::ParseOutput::new("foo", &s);
let expected_json =
Expand All @@ -32,7 +36,7 @@ fn p1(file: impl AsRef<std::path::Path> + std::fmt::Debug, fix: bool) {
}
println!("testing {file:?}");
let t = std::fs::read_to_string(&json).unwrap();
assert_eq!(&t, &expected_json, "Expected JSON: {t}")
assert_eq!(&t, &expected_json, "Expected JSON: {expected_json}")
}

pub fn find_all_files_matching_extension_recursively(
Expand Down
6 changes: 6 additions & 0 deletions v0.5/fastn-p1/t/001-empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"doc_name": "foo",
"items": [],
"line_starts": [],
"module_doc": null
}
33 changes: 33 additions & 0 deletions v0.5/fastn-p1/t/002-tutorial.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"doc_name": "foo",
"items": [
{
"span": {
"end": 50,
"start": 0
},
"value": "Comment"
},
{
"span": {
"end": 283,
"start": 221
},
"value": "Comment"
},
{
"span": {
"end": 320,
"start": 285
},
"value": {
"Error": "UnexpectedDocComment"
}
}
],
"line_starts": [],
"module_doc": {
"end": 220,
"start": 51
}
}

0 comments on commit 24af8cd

Please sign in to comment.