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 basic tests for PHP WASM grammar #1

Open
wants to merge 3 commits into
base: add-php-grammar
Choose a base branch
from

Conversation

claytonrcarter
Copy link

Hi there. As mentioned in pulsar-edit#852 (comment), these are some example tests that I updated from my original work on the legacy PHP tree-sitter grammar.

The first commit runs, but most of the tests fail because it's trying to match the output of the TM grammar pretty closely. The second commit updates the tests to better match your code. eg I removed the punctuation scopes for semicolons, etc. Note that the second commit still has plenty of failures, because I found a few places where the new grammar maybe wasn't covering all of the bases. (eg ??=, % and instanceof).

The failing output I see is:

❯ ATOM_DEV_RESOURCE_PATH=~/src/Atom/pulsar/worktrees/add-php-grammar pulsar -d -t spec/wasm-tree-sitter-spec.js
...FF..F.FF.F.

Tree-sitter PHP grammar
  operators
    combined operators
      it scopes ??=

  Failure: Scopes did not match at position [1, 6]:
$test ??= true;
      ^
  These scopes were expected but not received:
      keyword.operator.assignment.compound.php
  These scopes were received but not expected:


          at jasmine.Spec.<anonymous> (/Users/crcarter/src/Atom/pulsar/worktrees/add-php-grammar/packages/language-php/spec/wasm-tree-sitter-spec.js:82:24)
    it scopes %

  Failure: Scopes did not match at position [1, 2]:
1 % 2;
  ^
  These scopes were expected but not received:
      keyword.operator.arithmetic.php
  These scopes were received but not expected:


        at jasmine.Spec.<anonymous> (/Users/crcarter/src/Atom/pulsar/worktrees/add-php-grammar/packages/language-php/spec/wasm-tree-sitter-spec.js:53:22)
    it scopes instanceof

  Failure: Scopes did not match at position [1, 3]:
$x instanceof Foo;
   ^
  These scopes were expected but not received:
      keyword.operator.type.php
  These scopes were received but not expected:


        at jasmine.Spec.<anonymous> (/Users/crcarter/src/Atom/pulsar/worktrees/add-php-grammar/packages/language-php/spec/wasm-tree-sitter-spec.js:62:22)
  use declarations
    it scopes basic use statements

  Failure: Scopes did not match at position [1, 6]:
use My\Full\NSname;
      ^
  These scopes were expected but not received:
      punctuation.operator.namespace.php
  These scopes were received but not expected:
      keyword.operator.namespace.php

        at jasmine.Spec.<anonymous> (/Users/crcarter/src/Atom/pulsar/worktrees/add-php-grammar/packages/language-php/spec/wasm-tree-sitter-spec.js:110:22)

  Failure: Scopes did not match at position [1, 11]:
use My\Full\NSname;
           ^
  These scopes were expected but not received:
      punctuation.operator.namespace.php
  These scopes were received but not expected:
      keyword.operator.namespace.php

        at jasmine.Spec.<anonymous> (/Users/crcarter/src/Atom/pulsar/worktrees/add-php-grammar/packages/language-php/spec/wasm-tree-sitter-spec.js:112:22)
  classes
    it scopes class declarations

  Failure: Scopes did not match at position [1, 0]:
class Test {}
^
  These scopes were expected but not received:
      storage.type.class.php
  These scopes were received but not expected:
      storage.type.TYPE.php

        at jasmine.Spec.<anonymous> (/Users/crcarter/src/Atom/pulsar/worktrees/add-php-grammar/packages/language-php/spec/wasm-tree-sitter-spec.js:121:22)
    it scopes class modifiers

  Failure: Scopes did not match at position [1, 9]:
abstract class Test {}
         ^
  These scopes were expected but not received:
      storage.type.class.php
  These scopes were received but not expected:
      storage.type.TYPE.php

        at jasmine.Spec.<anonymous> (/Users/crcarter/src/Atom/pulsar/worktrees/add-php-grammar/packages/language-php/spec/wasm-tree-sitter-spec.js:140:22)

  Failure: Scopes did not match at position [1, 6]:
final class Test {}
      ^
  These scopes were expected but not received:
      storage.type.class.php
  These scopes were received but not expected:
      storage.type.TYPE.php

        at jasmine.Spec.<anonymous> (/Users/crcarter/src/Atom/pulsar/worktrees/add-php-grammar/packages/language-php/spec/wasm-tree-sitter-spec.js:145:22)


Finished in 3.223 seconds
14 tests, 53 assertions, 8 failures, 0 skipped

Obviously happy to make any changes you'd like to see, or just to close this if you're not interested. Thank you!

@claytonrcarter
Copy link
Author

I just added a few more tests for the cases I mentioned in pulsar-edit#852 (comment), eg readonly and opening and closing tags. Hope these help!

@savetheclocktower
Copy link
Owner

Sorry, I didn't get a notification when you opened this. Even though it's my own repo! I will look over it when I can, but feel free to remind me if it's been a week or so.

These tests and the scopes are meant to mimic the TextMate grammar and scopes,
but the new tree-sitter grammar deviates in a few ways. The adjustments needed
to make these pass are in the next commit.
This updates the tests to match the output of the new WASM grammar, except
where I think the WASM grammar may be wrong.
These cover some of the cases mentioned at
pulsar-edit#852 (comment)
@claytonrcarter
Copy link
Author

Sorry, I didn't get a notification when you opened this.

No worries! I just rebased this onto your latest branch. Depending on what you think of #2, I may retarget this at that branch to add coverage for my changes. Maybe just for my own sanity?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants