Skip to content

Commit

Permalink
fix: Correct order of #ifdef'd member decls.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Nov 9, 2024
1 parent bb7a411 commit 4d22ca2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Language/Cimple/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ MemberDecl :: { NonTerm }
MemberDecl
: VarDecl ';' { Fix $ MemberDecl $1 Nothing }
| VarDecl ':' LIT_INTEGER ';' { Fix $ MemberDecl $1 (Just $3) }
| PreprocIfdef(MemberDeclList) { $1 }
| PreprocIfdef(MemberDecls) { $1 }
| Comment { $1 }

TypedefDecl :: { NonTerm }
Expand Down
21 changes: 21 additions & 0 deletions test/Language/Cimple/PrettySpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ spec = do
, "} Foo;"
]

it "pretty-prints ifdef'd struct members in the correct order" $
compact (unlines
[ "typedef struct Foo {"
, " int32_t a;"
, "#ifdef ENABLE_XY"
, " int32_t x;"
, " int32_t y;"
, "#endif /* ENABLE_XY */"
, "} Foo;"
])
`shouldBe` unlines
[ "typedef struct Foo {"
, "int32_t a;"
, "#ifdef ENABLE_XY"
, "int32_t x;"
, ""
, "int32_t y;"
, "#endif /* ENABLE_XY */"
, "} Foo;"
]

it "respects newlines at end of comments" $ do
compact "/* foo bar */" `shouldBe` "/* foo bar */\n"
compact "/* foo bar\n */" `shouldBe` "/* foo bar\n */\n"
Expand Down

0 comments on commit 4d22ca2

Please sign in to comment.