-
Notifications
You must be signed in to change notification settings - Fork 0
added tests #5
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
added tests #5
Conversation
|
Could |
no, they work differently: actual = a: 1, b: 2
expected = a: 1 # don't care about `b`, ignore it
hasActualAllExpectedPropsAndAreTheyEqual actual, expected
# undefined
deepStrictEqual actual, expected # throws
# AssertionError: { a: 1, b: 2 } deepStrictEqual { a: 1 }
do those tests look alright so far? i got a feeling that i’m doing something awfully wrong. |
tests are mostly complete now. also included one for our helper function.
|
@GeoffreyBooth I believe this is ready for a review. |
GeoffreyBooth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work so far! All minor notes.
test/abstract_syntax_tree.coffee
Outdated
|
|
||
| testExpressions = (code, expected) -> | ||
| ast = getExpressions code | ||
| return console.log ast unless expected? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I added these console.log lines as helpers for writing the tests, so I could figure out what expected should be. Now that all the tests are written we don’t need them anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added those logs and would leave them there for future edits. They are very convenient.
test/abstract_syntax_tree.coffee
Outdated
|
|
||
| testExpression = (code, expected) -> | ||
| ast = getExpression code | ||
| return console.log ast unless expected? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here’s the other one.
test/abstract_syntax_tree.coffee
Outdated
| x: [3, 2, 1] | ||
|
|
||
| check 'Partial object comparison', doesNotThrow, | ||
| a: c: 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line looks confusing. Is it:
a:
c: 2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is. To me those aren't confusing at all. It's just coffeescript.
test/abstract_syntax_tree.coffee
Outdated
| body: | ||
| type: 'Value' | ||
| isDefaultValue: no | ||
| base: value: 'i' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general can we avoid implicit objects as object values? It seems like a recipe for trouble later.
base:
value: 'i'There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we could. But not only would it make the file much longer, it would also make it less readable IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I’m mistaken, it’s not the coding style of the rest of the codebase. We try to keep things consistent.
| testExpression '///^#{flavor}script$///', | ||
| type: 'RegexWithInterpolations' | ||
|
|
||
| # TODO: Shouldn't there be more info we can check for? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you check for the body of the regex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what i wanted to do but it seems the information is missing. Here's the full AST from getExpressions:
[
{
type: 'RegexWithInterpolations',
loc: {
start: {line: 0, column: 0},
end: {line: 0, column: 22}
}
}
]There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think this is the kind of thing that @helixbass is adding in his work.
test/abstract_syntax_tree.coffee
Outdated
| clause: type: 'Class' | ||
|
|
||
| test "AST as expected for ExportAllDeclaration node", -> | ||
| # TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add this one, couldn’t we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I have no idea what it could be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export * from "module-name"
test/abstract_syntax_tree.coffee
Outdated
| # TODO | ||
|
|
||
| test "AST as expected for ModuleSpecifierList node", -> | ||
| # TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ModuleSpecifierList is a parent class that would never be output on its own. If that’s correct, we shouldn’t need to test it (well, we couldn’t, actually).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was under the same impression. It's likely the base class for ExportSpecifierList and ImportSpecifierList. Same would go for the other Module nodes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it’s never output in the AST, we don’t need a TODO for it.
test/abstract_syntax_tree.coffee
Outdated
| # TODO: Test object splats. | ||
|
|
||
| test "AST as expected for Expansion node", -> | ||
| # TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add this one, and the following?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea what they could be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expansion is defined in a comment as “Used to skip values inside an array destructuring (pattern matching) or parameter list.” I wonder if this node is even used anymore, now that we use ES destructuring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elision is just [,a, , , b, , c, ,] (the skipped elements). Is that not output in the AST?
| base: value: 'o' | ||
| , | ||
| originalValue: '/' | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For strings, we will want to test (eventually) that the AST outputs the string delimiter (single quote or double quote). I assume that’s not output yet, so maybe add a TODO?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That information is available in the quote property and is even checked here. I added the check to StringLiteral now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry I didn’t notice. Good catch.
| base: value: '42' | ||
| isDefaultValue: no | ||
|
|
||
| # TODO: File issue for compile error when using `then` or `;` where `\n` is rn. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From playing around for a bit it seemed impossible to enter the Switch body without an actual linebreak. From my understanding a semicolon or the then keyword should allow for it.
I think you’re on the right track. In general we probably want to check more values of things, like the value of a string or the name of a function/ As for |
|
Replied to your comments.
Absolutely. But I feel that the current AST generator isn't quite there yet. Some information seems missing (
It seems that If i followed correctly then someone (@helixbass?) is still working on AST output. The tests I wrote in this PR so far all pass on the current compiler output, which i expect will still change as work on the AST generator progresses. I'd rather not make the tests too strict just yet before the AST is final. |
|
@Inve1951 yup I have been working on AST generation on a separate branch Wherever possible, I've been making the structure of our AST nodes match the corresponding Babel AST nodes, as there are lots of upsides to compatibility. Then when there are Coffeescript-specific things, I've exposed additional fields on some node types and created a couple new node types that don't have a comparable node type in JS @GeoffreyBooth and I discussed a strategy for getting the work I've been doing merged into our So basically I'll be prepared to pick up the existing tests on this branch in whatever state they're in and tweak them/add to them as I go If you're curious, I'd recommend astexplorer.net as a great way of exploring the different AST node types - choosing the |
|
@helixbass i cloned your prettier branch to see how much the AST differs. However it fails to build the compiler as it can't handle the object splats. I've tried installing |
|
@Inve1951 ah yeah I recall the discussion that there shouldn't be object spread syntax in the Coffeescript codebase so as to still support Node 6.x. So I'll have to go through and update places where I'm using it In the meantime, if upgrading Node isn't an option, I'm not sure exactly how you'd have to configure Babel to get it to post-process the compiled |
|
Please merge @helixbass I’ve been using Building the compiler doesn’t use Babel, other than for building the browser compiler. On |
|
Updated per your comments. These node types are still left without any tests: |
…d, built files in /lib; the build parts of CI are only a test that the build process succeeds, so we shouldn't be testing the output of the CI build steps
added a couple tests
i'm aware not all in there is ideal but please point me in the right direction
i thought to maybe move
hasActualAllExpectedPropsAndAreTheyEqualto the top,give it array support(already has), and use it for all the tests