Skip to content

Commit

Permalink
second attempt to fix typedef comment issues (#405)
Browse files Browse the repository at this point in the history
* second attempt to fix typedef comment issues
  • Loading branch information
AlexHaxe authored May 2, 2018
1 parent 67073cf commit 091d730
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- Fixed bad offset crash with C++ build on7 Windows 10 [#398](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/398)
- Fixed object declaration handling [#399](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/399)
- Fixed false positives for files with UTF-8 characters when running as vscode-checkstyle [#402](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/402)
- Fixed comments in typedefs [#404](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/404)
- Fixed comments in typedefs [#404](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/404) + [#405](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/405)
- Refactored content handling to use Bytes instead of String (should fix [#98](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/98)) [#402](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/402)
- Added unittests for ParserQueue and CheckerPool [#393](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/393)
- Added unittests for TokenTree structure verification [#400](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/400)
Expand Down
2 changes: 2 additions & 0 deletions src/checkstyle/token/walk/WalkFieldDef.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class WalkFieldDef {
parent = tok;
case At:
tempStore.push(WalkAt.walkAt(stream));
case Comment(_), CommentLine(_):
WalkComment.walkComment(stream, parent);
default:
break;
}
Expand Down
10 changes: 10 additions & 0 deletions test/token/TokenTreeBuilderParsingTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class TokenTreeBuilderParsingTest {
assertCodeParses(BLOCK_OBJECT_DECL_SAMPLES_ISSUE_396_3);
assertCodeParses(BLOCK_OBJECT_DECL_WITH_TERNARY);
assertCodeParses(TYPEDEF_COMMENTS);
assertCodeParses(TYPEDEF_COMMENTS_2);
}

public function assertCodeParses(code:String, ?pos:PosInfos) {
Expand Down Expand Up @@ -468,4 +469,13 @@ abstract TokenTreeBuilderParsingTests(String) to String {
var index:Int;
// æ@ð
}";

var TYPEDEF_COMMENTS_2 = "
typedef CheckFile = {
// °
var name:String;
var content:String;
// €łµ
var index:Int;
}";
}
29 changes: 29 additions & 0 deletions test/token/verify/VerifyTokenTreeTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,35 @@ class VerifyTokenTreeTest {
brOpen.childLast().is(BrClose).noChilds();
}

@Test
public function testTypedefComments2() {
var root:IVerifyTokenTree = buildTokenTree(TokenTreeBuilderParsingTests.TYPEDEF_COMMENTS_2);

// typedef CheckFile
var type:IVerifyTokenTree = root.childFirst().is(Kwd(KwdTypedef)).oneChild().childFirst().is(Const(CIdent("CheckFile")));
var brOpen:IVerifyTokenTree = type.childFirst().is(Binop(OpAssign)).oneChild().childFirst().is(BrOpen).childCount(6);
brOpen.childAt(0).is(CommentLine(" °"));

// var name:String;
var v:IVerifyTokenTree = brOpen.childAt(1).is(Kwd(KwdVar)).oneChild().childFirst().is(Const(CIdent("name"))).childCount(2);
v.childFirst().is(DblDot).oneChild().childFirst().is(Const(CIdent("String"))).noChilds();
v.childLast().is(Semicolon).noChilds();

// var content:String;
v = brOpen.childAt(2).is(Kwd(KwdVar)).oneChild().childFirst().is(Const(CIdent("content"))).childCount(2);
v.childFirst().is(DblDot).oneChild().childFirst().is(Const(CIdent("String"))).noChilds();
v.childLast().is(Semicolon).noChilds();

brOpen.childAt(3).is(CommentLine(" €łµ")).noChilds();

// var index:Int;
v = brOpen.childAt(4).is(Kwd(KwdVar)).oneChild().childFirst().is(Const(CIdent("index"))).childCount(2);
v.childFirst().is(DblDot).oneChild().childFirst().is(Const(CIdent("Int"))).noChilds();
v.childLast().is(Semicolon).noChilds();

brOpen.childLast().is(BrClose).noChilds();
}

function buildTokenTree(content:String):IVerifyTokenTree {
var builder:TestTokenTreeBuilder = new TestTokenTreeBuilder(content);
var root:TokenTree = new TokenTree(null, null, -1);
Expand Down

0 comments on commit 091d730

Please sign in to comment.