Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
Also fix up the patterns in light of said tests & code review.
  • Loading branch information
mAAdhaTTah committed Jun 12, 2018
1 parent 8c2b71f commit 32120e5
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 9 deletions.
18 changes: 9 additions & 9 deletions components/prism-tap.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Prism.languages.tap = {
pass: /(^|\n)( )*ok[^#\{\n]*/,
fail: /(^|\n)( )*not ok[^#\{\n]*/,
pragma: /(^|\n)( )*pragma ([+-])([a-z]+)(\n|$)/,
bailout: /(^|\n)( )*bail out!(.*)(\n|$)/i,
version: /(^|\n)( )*TAP version ([0-9]+)(\n|$)/i,
plan: /(^|\n)( )*([0-9]+)\.\.([0-9]+)( +#[^\n]*)?(\n|$)/m,
fail: /( )*not ok[^#{\n\r]*/,
pass: /( )*ok[^#{\n\r]*/,
pragma: /( )*pragma [+-][a-z]+/,
bailout: /( )*bail out!(.*)/i,
version: /( )*TAP version (\d+)/i,
plan: /( )*(\d+)\.\.(\d+)( +#.*)?/,
subtest: {
pattern: /(^|\n)( )*# Subtest(?:: (.*))?(\n|$)/,
pattern: /( )*# Subtest(?:: .*)?/,
greedy: true
},
punctuation: /[{}]/,
'comment': /#.*/,
directive: /#.*/,
yamlish: {
pattern: /(^|\n)(( )*( ))---\n(.*?\n)+\2\.\.\.(\n|$)/,
pattern: /(^[^\S\r\n]*)---(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?[^\S\r\n]*\.\.\.$/m,
lookbehind: true,
inside: Prism.languages.yaml,
alias: 'language-yaml'
Expand Down
13 changes: 13 additions & 0 deletions tests/languages/tap/bail_out_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Bail out! Couldn't connect to database.
bail out! Failed to call API.

----------------------------------------------------

[
["bailout", "Bail out! Couldn't connect to database."],
["bailout", "bail out! Failed to call API."]
]

----------------------------------------------------

Checks bail out
15 changes: 15 additions & 0 deletions tests/languages/tap/directive_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ok # SKIP test not written
ok 42 this is the description # TODO write test

----------------------------------------------------

[
["pass", "ok " ],
["directive", "# SKIP test not written"],
["pass", "ok 42 this is the description "],
["directive", "# TODO write test"]
]

----------------------------------------------------

Checks directives
17 changes: 17 additions & 0 deletions tests/languages/tap/pass_fail_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
not ok
not ok 42 this is the description of the test
ok
ok 42 this is the description of the test

----------------------------------------------------

[
["fail", "not ok" ],
["fail", "not ok 42 this is the description of the test"],
["pass", "ok" ],
["pass", "ok 42 this is the description of the test"]
]

----------------------------------------------------

Checks test pass & fail together correctly
13 changes: 13 additions & 0 deletions tests/languages/tap/plan_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
1..10
1..10 # directive

----------------------------------------------------

[
["plan", "1..10" ],
["plan", "1..10 # directive" ]
]

----------------------------------------------------

Checks TAP plan
13 changes: 13 additions & 0 deletions tests/languages/tap/pragma_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pragma +strict
pragma -strict

----------------------------------------------------

[
["pragma", "pragma +strict"],
["pragma", "pragma -strict"]
]

----------------------------------------------------

Checks pragma
11 changes: 11 additions & 0 deletions tests/languages/tap/version_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
TAP version 13

----------------------------------------------------

[
["version", "TAP version 13" ]
]

----------------------------------------------------

Checks TAP version
50 changes: 50 additions & 0 deletions tests/languages/tap/yamlish_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
ok
---
message: "Failed with error 'hostname peebles.example.com not found'"
severity: fail
data:
got:
hostname: 'peebles.example.com'
address: ~
expected:
hostname: 'peebles.example.com'
address: '85.193.201.85'
...

----------------------------------------------------

[
["pass", "ok"],
["yamlish", [
["punctuation", "---"],
["key", "message"],
["punctuation", ":"],
["string", "\"Failed with error 'hostname peebles.example.com not found'\""],
["key", "severity"],
["punctuation", ":"],
" fail\n ",
["key", "data"],
["punctuation", ":"],
["key", "got"],
["punctuation", ":"],
["key", "hostname"],
["punctuation", ":"],
["string", "'peebles.example.com'"],
["key", "address"],
["punctuation", ":"],
["null", "~"],
["key", "expected"],
["punctuation", ":"],
["key", "hostname"],
["punctuation", ":"],
["string", "'peebles.example.com'"],
["key", "address"],
["punctuation", ":"],
["string", "'85.193.201.85'"],
["punctuation", "..."]
]]
]

----------------------------------------------------

Checks yaml embedding

0 comments on commit 32120e5

Please sign in to comment.