class GtnLinterTest

Test case for the GTN linter

Public Instance Methods

test_doi() click to toggle source
# File bin/lint-test.rb, line 86
def test_doi
  text = "a\nfrom [Pedro LarraƱaga, 2006](https://doi.org/10.1093/bib/bbk007).\nasdf".split "\n"
  #          123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
  result = GtnLinter.check_dois(text)

  assert_equal(result[0]['location']['range']['start']['line'], 2)
  assert_equal(result[0]['location']['range']['start']['column'], 6)

  assert_equal(result[0]['location']['range']['end']['line'], 2)
  assert_equal(result[0]['location']['range']['end']['column'], 64 + 2) # Inexplicable.

  assert_equal(result[0]['suggestions'][0]['text'], '{% cite ... %}')
  assert_equal(result[0]['suggestions'][0]['range']['start']['line'], 2)
  assert_equal(result[0]['suggestions'][0]['range']['start']['column'], 6)
  assert_equal(result[0]['suggestions'][0]['range']['end']['line'], 2)
  assert_equal(result[0]['suggestions'][0]['range']['end']['column'], 64 + 2)

  text = "a\nfrom [Pedro LarraƱaga, 2006](https://doi.org/10.5281/zenodo.10238184212).\nasdf".split "\n"
  #          12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012
  result = GtnLinter.check_dois(text)
  assert_equal(result.length, 0)
end
test_fix_notoc() click to toggle source
# File bin/lint-test.rb, line 10
def test_fix_notoc
  text = "a\n{: .no_toc}\nasdf".split "\n"
  result = GtnLinter.fix_notoc(text)

  assert_equal(result[0]['location']['range']['start']['line'], 2)
  assert_equal(result[0]['location']['range']['start']['column'], 1)

  assert_equal(result[0]['location']['range']['end']['line'], 3)
  assert_equal(result[0]['location']['range']['end']['column'], 1)
end
test_youtube() click to toggle source
# File bin/lint-test.rb, line 35
def test_youtube
  text = "a\n<iframe .. youtube.com ... </iframe>x\nasdf".split "\n"
  result = GtnLinter.youtube_bad(text)

  assert_equal(result[0]['location']['range']['start']['line'], 2)
  assert_equal(result[0]['location']['range']['start']['column'], 1)

  assert_equal(result[0]['location']['range']['end']['line'], 2)
  assert_equal(result[0]['location']['range']['end']['column'], text[1].length)
end
testnew_title_() click to toggle source
# File bin/lint-test.rb, line 109
def testnew_title_
  [
    %w[tip Tip],
    %w[details Details],
    %w[hands_on Hands-on]
  ].each do |key, key_text|
    text = "a\n> ### {% icon #{key} %} #{key_text}: Blah\n> #{key_text} text\n{: .#{key}}".split "\n"
    #          12345678901234567890123456789012345678901234567890
    result = GtnLinter.new_more_accessible_boxes(text)

    assert_equal(result[0]['location']['range']['start']['line'], 2)
    assert_equal(result[0]['location']['range']['start']['column'], 3)

    assert_equal(result[0]['location']['range']['end']['line'], 2)
    assert_equal(result[0]['location']['range']['end']['column'], 24 + key.length + key_text.length + 1)

    k2 = key.gsub(/_/, '-')
    assert_equal(result[0]['suggestions'][0]['text'], "<#{k2}-title>Blah</#{k2}-title>")
  end

  # assert_equal(result[0]['suggestions'][0]['range']['start']['line'], 2)
  # assert_equal(result[0]['suggestions'][0]['range']['start']['column'], 9)
  # assert_equal(result[0]['suggestions'][0]['range']['end']['line'], 2)
  # assert_equal(result[0]['suggestions'][0]['range']['end']['column'], 9 + url.length)
end