Extend the tests in regexp/inspect_spec with over escaping combined with character classes
まだ誰も着手していません。
評価
調査の方向性
regexp/inspect_spec と既存の escaped backslash の例から始め、次に interpolated-regexp の挙動について language/case_spec を確認してください。列挙されている backslash と character-class のケース、および明示的な embedded-regexp の例をカバレッジに追加してください。関連する spec は、case ステートメントの挙動を変更せずにパスする必要があります。
索引モデルが issue の本文から書いたものです。
説明
The specs have one test for escaped backslashes in Regexp#inspect:
it "does not over escape" do
Regexp.new('\\\/').inspect.should == "/\\\\\\//"
end
The obvious implementation to make this spec pass is to simply escape every slash with another slash. This works in this case, but that causes an error in language/case_spec for something that is not related to the case statement:
it "tests with a regexp interpolated within another regexp" do
digits_regexp = /\d+/
case "foo43"
when /oo(#{digits_regexp})/
This results in a regexp /oo(?-mix:\\d+)/, which now expects a slash followed by one or more d characters. This does not match the input, but does not indicate the escaping as the issue.
I tested my implementation with the these specs added, but this was more or less brute forcing every possibility. Also, because Regexp.new takes a String which has an additional layer of escaping, I peferred the // notation.
Regexp.new('\d+').inspect.should == "/\\d+/"
/\d+/.inspect.should == "/\\d+/"
Regexp.new('\\d+').inspect.should == "/\\d+/"
/\\d+/.inspect.should == "/\\\\d+/"
Regexp.new('\\\d+').inspect.should == "/\\\\d+/"
/\\\d+/.inspect.should == "/\\\\\\d+/"
Regexp.new('\\\\d+').inspect.should == "/\\\\d+/"
/\\\\d+/.inspect.should == "/\\\\\\\\d+/"
I think it would be better to at least include the following cases:
/\d+/ # Output should have 1 not escaped slash, since this should not be escaped
/\\d+/ # Output should have 1 escaped slash (so 2 slashes), this should be escaped
/\\\d+/ # Output should have 1 escaped and 1 not escaped slash (so 3 slashes)
Furthermore, I think it would be better to add an explicit test for the regexp embedded in regexp scenario like there is in the case spec now, just to make the test a bit more explicit and decouple it from the case statement.
I'm not that familiar with this project and how things are structured, can I just add a few tests to the inspect spec of regexp, and make a new spec file for the embedding tests?
- 主要言語
- Ruby
- スター
- 622
- フォーク
- 402
- 平均マージ
- 14時間 51分
- マージ済み PR(30日)
- 6
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ruby/spec のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 38/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
palladius/rails8-app-on-gcp#145 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
rubocop/rubocop-rspec#2236 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
riscv/riscv-unified-db#2624 · リアクション 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100