Skip to content
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

Add TAP component #1430

Merged
merged 2 commits into from
Jun 16, 2018
Merged

Add TAP component #1430

merged 2 commits into from
Jun 16, 2018

Conversation

mAAdhaTTah
Copy link
Member

Still need to add tests, but I squashed the commits from #1089.

Includes build changes.
@mAAdhaTTah
Copy link
Member Author

@Golmote Not great at regex, so I'm struggling with getting yamlish working. Got an idea?

@mAAdhaTTah mAAdhaTTah mentioned this pull request May 27, 2018
@Golmote
Copy link
Contributor

Golmote commented May 27, 2018

I would say you need something like

	yamlish: {
		pattern: /(^[^\S\r\n]*)---(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?[^\S\r\n]*\.\.\.$/m,
		lookbehind: true,
		inside: Prism.languages.yaml,
		alias: 'language-yaml'
	}

The lookbehind (the first capturing group) matches the optional spaces before ---. Then we match multiple lines (?:.*(?:\r\n?|\n))*?, then we end up with the optional spaces and the final ....

This should match:

  ---
  but: this one
  has:
    - lots
    - of
    - stuff
  ...

@mAAdhaTTah
Copy link
Member Author

@Golmote I think we're looking good here. Let me know if you have suggestions.

@mAAdhaTTah mAAdhaTTah mentioned this pull request Jun 1, 2018
@mAAdhaTTah mAAdhaTTah changed the base branch from gh-pages to master June 5, 2018 20:13
Copy link
Contributor

@Golmote Golmote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you removed the (^|\n) parts that were checking for the beginning of the string in several regexps, I'm wondering if the ( )* parts are still needed. You might want to try removing them and see how the tests go.

Also, I commented inline on some more specific improvements.

Thanks for working on this!

@@ -0,0 +1,20 @@
Prism.languages.tap = {
fail: /( )*not ok[^#\{\n]*/,
pass: /( )*ok[^#\{\n]*/,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need to escape the { in the character class in those two regexps.
Also, we should probably include \r in the character class too, to handle the different line endings.

Prism.languages.tap = {
fail: /( )*not ok[^#\{\n]*/,
pass: /( )*ok[^#\{\n]*/,
pragma: /( )*pragma ([\+-])([a-z]+)/,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need to escape the + in the character class.
Also, the last two pairs of parentheses are not needed.

pragma: /( )*pragma ([\+-])([a-z]+)/,
bailout: /( )*bail out!(.*)/i,
version: /( )*TAP version ([0-9]+)/i,
plan: /( )*([0-9]+)\.\.([0-9]+)( +#[^\n]*)?/m,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace all occurrences of ([0-9]+) with \d+ (no parentheses needed here) in those two regexps.
Also, it seems the m could be removed, since the regexp does not use ^ or $ assertions.
Finally, the [^\n]* part could probably be replaced with .*.

version: /( )*TAP version ([0-9]+)/i,
plan: /( )*([0-9]+)\.\.([0-9]+)( +#[^\n]*)?/m,
subtest: {
pattern: /( )*# Subtest(?:: (.*))?/,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parentheses around (.*) are not needed.


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

Checks test pass & fail together correctly
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering you added this test, I think it can be overkill to also have the pass_feature and fail_feature tests separately.

@@ -0,0 +1,11 @@
1..10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plan pattern in the language definition seems to also include an optional directive (e.g. # foobar) after the numbers part. If this is what is intended, we should add a test for it here.

@mAAdhaTTah
Copy link
Member Author

@Golmote Updated.

@Golmote
Copy link
Contributor

Golmote commented Jun 16, 2018

Looks quite good to me. There are still a few nitpicks, but I won't mind if this is merged as is.

You did not give me feedback regarding this comment. Did you give it a try? Are those needed?

Since you removed the (^|\n) parts that were checking for the beginning of the string in several regexps, I'm wondering if the ( )* parts are still needed. You might want to try removing them and see how the tests go.

Also I can still see some unneeded parentheses:

  • around (.*) in bailout
  • around (\d+) in version
  • around (\d+) in plan.

Finally, all the remaining groups, expect in the yamlish pattern that uses lookbehind, could be made non-capturing using ?:.

Also fix up the patterns in light of said tests & code review.
@mAAdhaTTah
Copy link
Member Author

I missed that comment the first time around. Made the changes suggested; tests still pass. Also added the minified file.

@mAAdhaTTah mAAdhaTTah merged commit 09b56af into master Jun 16, 2018
@mAAdhaTTah mAAdhaTTah deleted the add-tap branch June 16, 2018 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants