<commit_before>require 'spec_helper'

describe "r" do
  # TODO:
  #   I don't have any background in ruby, so I'll try to my best to articulate
  #   some tests and hopefully someone with some ruby background can pitch in.
  #
  #
  # # sj#r#SplitFuncall() with named args
  #   given text and issuing split:
  #     
  #     print(1, 2, 3)
  #           ^ normal! gS
  #
  #
  #   expect the following (indentation may be altered by global vim R
  #   indentation setting `g:r_indent_align_args`):
  #     
  #     # if `let g:r_indent_align_args = 0`
  #     print(
  #       1,
  #       a = 2,
  #       3
  #     )
  #
  #     # if `let g:r_indent_align_args = 1`
  #     print(1,
  #           a = 2,
  #           3)
  #
  #
  # # sj#r#SplitFuncall() with nested calls
  #   given text and issuing split:
  #     
  #     print(1, c(1, 2, 3), 3)
  #           ^ normal! gS
  #
  #   expect output:
  #
  #     # if `let g:r_indent_align_args = 0`
  #     print(
  #       1,
  #       c(1, 2, 3),
  #       3
  #     )
  #
  #     # if `let g:r_indent_align_args = 1`
  #     print(1,
  #           c(1, 2, 3),
  #           3)
  #
  #
  # # sj#r#SplitFuncall() on a nested call function name should behave similarly
  # # as the outer parenthesis 
  #   given text and issuing split:
  #     
  #     print(1, c(1, 2, 3), 3)
  #              ^ normal! gS
  #
  #   expect output:
  #
  #     # if `let g:r_indent_align_args = 0`
  #     print(
  #       1,
  #       c(1, 2, 3),
  #       3
  #     )
  #
  #     # if `let g:r_indent_align_args = 1`
  #     print(1,
  #           c(1, 2, 3),
  #           3)
  #
  #
  # # sj#r#SplitFuncall() on a nested call function args should split inner
  # # function args
  #   given text and issuing split:
  #
  #     print(1, c(1, 2, 3), 3)
  #                ^ normal! gS
  #
  #   expect output:
  #
  #     # if `let g:r_indent_align_args = 0`
  #     print(1, c(
  #         1, 
  #         2, 
  #         3
  #         ), 3)
  #
  #     # if `let g:r_indent_align_args = 1`
  #     print(1, c(1, 
  #                2, 
  #                3), 3)
  #
  # # sj#r#JoinFuncall() on a function call should join function args
  #   given text and issuing join:
  #
  #     print(
  #       1, 
  #       2, # <- normal! gJ
  #       3
  #     )
  #
  #   expect output:
  #
  #     print(1, 2, 3)
  #
  #
  # # sj#r#JoinFuncall() on a nested call function args should join inner
  # # function args
  #   given text and issuing join:
  #
  #     print(
  #       1, 
  #       c(
  #         1, 
  #         2, # <- normal! gJ
  #         3
  #         ), 
  #       3
  #     )
  #
  #   expect output:
  #
  #     print(
  #       1, 
  #       c(1, 2, 3), 
  #       3
  #     )
  #
end<commit_msg>Implement R specs<commit_after>require 'spec_helper'

describe "R" do
  let(:filename) { 'test.r' }

  before :each do
    vim.set(:expandtab)
    vim.set(:shiftwidth, 2)
  end

  after :each do
    vim.command('silent! unlet g:r_indent_align_args')
  end

  specify "function calls with align_args = 0" do
    vim.command('let g:r_indent_align_args = 0')

    set_file_contents 'print(1, a = 2, 3)'
    vim.search('1,')
    split

    assert_file_contents <<~EOF
      print(
        1,
        a = 2,
        3
      )
    EOF

    join

    assert_file_contents 'print(1, a = 2, 3)'
  end

  specify "function calls with align_args = 1" do
    vim.command('let g:r_indent_align_args = 1')

    set_file_contents 'print(1, a = 2, 3)'
    vim.search('1,')
    split

    assert_file_contents <<~EOF
      print(1,
            a = 2,
            3)
    EOF

    join

    assert_file_contents 'print(1, a = 2, 3)'
  end

  specify "function calls with nested calls" do
    vim.command('let g:r_indent_align_args = 1')
    set_file_contents 'print(1, c(1, 2, 3), 3)'

    # On start of nested function
    vim.search('c(')
    split

    assert_file_contents <<~EOF
      print(1,
            c(1, 2, 3),
            3)
    EOF

    join

    assert_file_contents 'print(1, c(1, 2, 3), 3)'

    # Inside nested function
    vim.search('c(')
    vim.search('1,')
    split

    assert_file_contents <<~EOF
      print(1, c(1,
                 2,
                 3), 3)
    EOF

    join

    assert_file_contents 'print(1, c(1, 2, 3), 3)'
  end
end
{'fraction_non_alphanumeric': 0.12694722157637758, 'fraction_numerical': 0.030225528946756567, 'mean_word_length': 1.5500889152341435, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, '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': '3475590', 'n_tokens_mistral': 1753, 'n_tokens_neox': 1627, 'n_words': 413}