Fix bug in character rule equality
This commit is contained in:
parent
7f62e752be
commit
28e10dc722
2 changed files with 24 additions and 0 deletions
|
|
@ -141,6 +141,28 @@ describe("rule transitions", []() {
|
|||
})
|
||||
}})));
|
||||
});
|
||||
|
||||
describe("regression tests (somewhat redundant, should maybe be deleted later)", []() {
|
||||
it("handles sequences that start with repeating characters", [&]() {
|
||||
auto rule = seq({
|
||||
choice({
|
||||
repeat(character({ '"' }, false)),
|
||||
blank(),
|
||||
}),
|
||||
character('"'),
|
||||
});
|
||||
|
||||
AssertThat(rule_transitions(rule), Equals(transition_map<Rule, Rule>({
|
||||
{ character({ '"' }, false), seq({
|
||||
choice({
|
||||
repeat(character({ '"' }, false)),
|
||||
blank(),
|
||||
}),
|
||||
character('"'), }) },
|
||||
{ character('"'), blank() },
|
||||
})));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("checking if rules can be blank", [&]() {
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ namespace tree_sitter {
|
|||
bool Character::operator==(const Rule &rule) const {
|
||||
const Character *other = dynamic_cast<const Character *>(&rule);
|
||||
if (!other) return false;
|
||||
if (other->sign != sign) return false;
|
||||
auto size = matches.size();
|
||||
if (other->matches.size() != size) return false;
|
||||
for (int i = 0; i < size; i++)
|
||||
|
|
@ -71,6 +72,7 @@ namespace tree_sitter {
|
|||
|
||||
string Character::to_string() const {
|
||||
string prefix("#<char");
|
||||
if (!sign) prefix += " (not)";
|
||||
for (auto &match : matches)
|
||||
prefix += " " + match.to_string();
|
||||
return prefix + ">";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue