From ae251bb33af8404686b3fb34dd7feeeaa5ef6fdf Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Mon, 3 May 2021 13:46:42 +0000 Subject: [PATCH] Fix regexp latin property mapping --- Changelog.md | 8 ++++++++ lib/mutant/ast/regexp/transformer/direct.rb | 1 + lib/mutant/ast/types.rb | 1 + meta/regexp/regexp_latin_property.rb | 8 ++++++++ spec/unit/mutant/ast/regexp_spec.rb | 5 +++++ 5 files changed, 23 insertions(+) create mode 100644 meta/regexp/regexp_latin_property.rb diff --git a/Changelog.md b/Changelog.md index 9b51db2dd..0440b4759 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,11 @@ +# v0.10.31 2021-05-03 + +* [#](https://github.com/mbj/mutant/pull/) + Add mapping for latin regexp properties to fix crash on mutating + `p{Latin}` regexp nodes. + + [Fix #1231] + # v0.10.30 2021-04-25 * [#1229](https://github.com/mbj/mutant/pull/1229) diff --git a/lib/mutant/ast/regexp/transformer/direct.rb b/lib/mutant/ast/regexp/transformer/direct.rb index 4c956d015..6b0187d44 100644 --- a/lib/mutant/ast/regexp/transformer/direct.rb +++ b/lib/mutant/ast/regexp/transformer/direct.rb @@ -74,6 +74,7 @@ class ASTToExpression < Transformer::ASTToExpression [:regexp_katakana_property, [:property, :katakana, '\p{Katakana}'], ::Regexp::Expression::UnicodeProperty::Script], [:regexp_letter_property, [:property, :letter, '\p{L}'], ::Regexp::Expression::UnicodeProperty::Letter::Any], [:regexp_linebreak_type, [:type, :linebreak, '\R'], ::Regexp::Expression::CharacterType::Linebreak], + [:regexp_latin_property, [:property, :latin, '\p{Latin}'], ::Regexp::Expression::UnicodeProperty::Script], [:regexp_lower_posixclass, [:posixclass, :lower, '[:lower:]'], ::Regexp::Expression::PosixClass], [:regexp_mark_keep, [:keep, :mark, '\K'], ::Regexp::Expression::Keep::Mark], [:regexp_match_start_anchor, [:anchor, :match_start, '\\G'], ::Regexp::Expression::Anchor::MatchStart], diff --git a/lib/mutant/ast/types.rb b/lib/mutant/ast/types.rb index 45f4a19e6..460656c8c 100644 --- a/lib/mutant/ast/types.rb +++ b/lib/mutant/ast/types.rb @@ -107,6 +107,7 @@ module Types # rubocop:disable Metrics/ModuleLength regexp_interval_close_escape regexp_interval_open_escape regexp_katakana_property + regexp_latin_property regexp_letter_property regexp_linebreak_type regexp_literal_escape diff --git a/meta/regexp/regexp_latin_property.rb b/meta/regexp/regexp_latin_property.rb new file mode 100644 index 000000000..e32ac1b12 --- /dev/null +++ b/meta/regexp/regexp_latin_property.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +Mutant::Meta::Example.add :regexp, :regexp_latin_property do + source('/p{Latin}/') + + singleton_mutations + regexp_mutations +end diff --git a/spec/unit/mutant/ast/regexp_spec.rb b/spec/unit/mutant/ast/regexp_spec.rb index dc63b8160..e2ab5c9a8 100644 --- a/spec/unit/mutant/ast/regexp_spec.rb +++ b/spec/unit/mutant/ast/regexp_spec.rb @@ -657,6 +657,11 @@ def self.expect_mapping(regexp, type, &block) s(:regexp_hiragana_property)) end +RegexpSpec.expect_mapping(/\p{Latin}/, :regexp_latin_property) do + s(:regexp_root_expression, + s(:regexp_latin_property)) +end + RegexpSpec.expect_mapping(/\p{Katakana}/, :regexp_katakana_property) do s(:regexp_root_expression, s(:regexp_katakana_property))