Skip to content

Commit 9804256

Browse files
committed
Ensure that clicking on the MIR source links highlights the text
1 parent 2d32a22 commit 9804256

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'spec_helper'
2+
require 'support/editor'
3+
require 'support/playground_actions'
4+
5+
RSpec.feature "Highlighting MIR output", type: :feature, js: true do
6+
include PlaygroundActions
7+
8+
before do
9+
visit '/'
10+
editor.set(code)
11+
in_build_menu { click_on("MIR") }
12+
end
13+
14+
scenario "error locations are links" do
15+
within('.output-mir') do
16+
click_link('src/main.rs:4:14: 4:19', match: :first)
17+
end
18+
expect(editor).to have_highlighted_text('a + b')
19+
end
20+
21+
def editor
22+
Editor.new(page)
23+
end
24+
25+
def code
26+
<<~EOF
27+
fn main() {
28+
let a = 1;
29+
let b = 2;
30+
let _c = a + b;
31+
}
32+
EOF
33+
end
34+
end

tests/spec/support/editor.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,17 @@ def set(text)
1515
def has_line?(text)
1616
page.has_css? '.ace_line', text: text
1717
end
18+
19+
def has_highlighted_text?(text)
20+
page.within('.editor .ace_text-input', visible: :any) do
21+
selected = page.evaluate_script <<~JS
22+
(() => {
23+
const editor = document.querySelector('.ace_editor').env.editor;
24+
return editor.getSelectedText();
25+
})()
26+
JS
27+
28+
selected == text
29+
end
30+
end
1831
end

0 commit comments

Comments
 (0)