<commit_before>require 'spec_helper'
require 'support/editor'
require 'support/playground_actions'

RSpec.feature "Editor assistance for common code modifications", type: :feature, js: true do
  include PlaygroundActions

  before { visit '/' }

  scenario "building code without a main method offers adding one" do
    editor.set <<~EOF
      fn example() {}
    EOF
    click_on("Build")

    within('.output-warning') do
      click_on("add a main function")
    end

    within('.editor') do
      expect(editor).to have_line 'println!("Hello, world!")'
    end
  end

  scenario "using an unstable feature offers adding the feature flag" do
    in_channel_menu { click_on("Nightly") }
    editor.set <<~EOF
      fn foo<const T: usize>() {}
    EOF
    click_on("Build")

    within('.output-stderr') do
      click_on("add `#![feature(const_generics)]`")
    end

    within('.editor') do
      expect(editor).to have_line '#![feature(const_generics)]'
    end
  end

  scenario "using a type that hasn't been imported offers importing it" do
    editor.set <<~EOF
      fn example(_: HashMap) {}
    EOF
    click_on("Build")

    within('.output-stderr') do
      click_on("use std::collections::HashMap;")
    end

    within('.editor') do
      expect(editor).to have_line 'use std::collections::HashMap;'
    end
  end

  scenario "triggering a panic offers enabling backtraces" do
    editor.set <<~EOF
      fn main() {
          panic!("Oops");
      }<commit_msg>Update test for renamed feature flag<commit_after>require 'spec_helper'
require 'support/editor'
require 'support/playground_actions'

RSpec.feature "Editor assistance for common code modifications", type: :feature, js: true do
  include PlaygroundActions

  before { visit '/' }

  scenario "building code without a main method offers adding one" do
    editor.set <<~EOF
      fn example() {}
    EOF
    click_on("Build")

    within('.output-warning') do
      click_on("add a main function")
    end

    within('.editor') do
      expect(editor).to have_line 'println!("Hello, world!")'
    end
  end

  scenario "using an unstable feature offers adding the feature flag" do
    in_channel_menu { click_on("Nightly") }
    editor.set <<~EOF
      fn foo<const T: usize>() {}
    EOF
    click_on("Build")

    within('.output-stderr') do
      click_on("add `#![feature(min_const_generics)]`")
    end

    within('.editor') do
      expect(editor).to have_line '#![feature(min_const_generics)]'
    end
  end

  scenario "using a type that hasn't been imported offers importing it" do
    editor.set <<~EOF
      fn example(_: HashMap) {}
    EOF
    click_on("Build")

    within('.output-stderr') do
      click_on("use std::collections::HashMap;")
    end

    within('.editor') do
      expect(editor).to have_line 'use std::collections::HashMap;'
    end
  end

  scenario "triggering a panic offers enabling backtraces" do
    editor.set <<~EOF
      fn main() {
          panic!("Oops");
      }
{'fraction_non_alphanumeric': 0.12320053565450284, 'fraction_numerical': 0.0, 'mean_word_length': 3.1270718232044197, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3615634', 'n_tokens_mistral': 910, 'n_tokens_neox': 888, 'n_words': 269}