Skip to content

Commit

Permalink
Test types with tsd
Browse files Browse the repository at this point in the history
  • Loading branch information
hildjj committed May 28, 2021
1 parent f6d4493 commit 5bfe2fd
Show file tree
Hide file tree
Showing 6 changed files with 2,813 additions and 9,979 deletions.
44 changes: 44 additions & 0 deletions examples/fizzbuzz.peggy
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
This grammar aims to have one of every Peggy syntax.
It parses the output of a fizz-buzz (https://en.wikipedia.org/wiki/Fizz_buzz)
program (plus a few extensions) for correctness.
*/
{{
const NUMS = [3, 5];
}}
{
let currentNumber = (options.start == null) ? 1 : options.start|0;
}

top = c:count* { return c.filter(fb => fb) }

count
= end_comment "\n" { return }
/ comment "\n" { return }
/ comment? fb:line (comment / end_comment)? "\n" {
currentNumber++;
return fb;
}

comment "comment"
= _ "/*" (!"*/" .)* "*/" _

end_comment
= _ "//" [^\n]+

line
= @n:number &{ return (n === currentNumber) && NUMS.every(d => n % d) }
/ fizzbuzz
/ fizz
/ buzz

fizzbuzz = f:fizz _ b:buzz { return f + b }
fizz = @"fizz"i !{ return currentNumber % 3 }
buzz = @"buzz"i !{ return currentNumber % 5 }

// Arbitrary requirement needing &
number "number without trailing comment"
= "0x" n:$[0-9a-f]i+ &"\n" { return parseInt(n, 16) }
/ n:$[0-9]+ &"\n" { return parseInt(n, 10) }

_ = $[ \t]*
6 changes: 5 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ module.exports = {
"<rootDir>/test"
],
"testMatch": [
"**/*.spec.js"
"**/*.spec.js",
"**/*.test-d.ts"
],
"transform": {
"^.+\\.ts$": "ts-jest",
}
};
Loading

0 comments on commit 5bfe2fd

Please sign in to comment.