File: shell_spec.rb

package info (click to toggle)
ruby-rouge 4.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,844 kB
  • sloc: ruby: 38,489; sed: 2,071; perl: 152; makefile: 8
file content (83 lines) | stat: -rw-r--r-- 2,607 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

describe Rouge::Lexers::Shell do
  let(:subject) { Rouge::Lexers::Shell.new }

  include Support::Lexing
  it 'parses a basic shell string' do
    tokens = subject.lex('foo=bar').to_a
    assert { tokens.size == 3 }
    assert { tokens.first[0] == Token['Name.Variable'] }
  end

  it 'parses case statements correctly' do
    assert_no_errors <<-sh
      case $foo in
        a) echo "LOL" ;;
      esac
    sh
  end

  it 'parses case statement with globs correctly' do
    assert_no_errors <<-sh
      case $foo in
        a[b]) echo "LOL" ;;
      esac
    sh
  end

  it 'parses comments correctly' do
    tokens = subject.lex('foo=bar # this is a comment').to_a
    assert { tokens.size == 4 }
    assert { tokens.last[0] == Token['Comment'] }
  end

  describe 'guessing' do
    include Support::Guessing

    it 'guesses by filename' do
      assert_guess :filename => 'foo.sh'
      assert_guess :filename => 'foo.zsh'
      assert_guess :filename => 'foo.ksh'
      assert_guess :filename => 'foo.bash'
      assert_guess :filename => 'APKBUILD'
      assert_guess :filename => 'PKGBUILD'
      assert_guess :filename => 'foo.ebuild'
      assert_guess :filename => 'foo.eclass'
      assert_guess :filename => 'foo.exheres-0'
      assert_guess :filename => 'foo.exlib'
      assert_guess :filename => '.zshenv'
      assert_guess :filename => '.zprofile'
      assert_guess :filename => '.zshrc'
      assert_guess :filename => '.zlogin'
      assert_guess :filename => '.zlogout'
      assert_guess :filename => 'zshenv'
      assert_guess :filename => 'zprofile'
      assert_guess :filename => 'zshrc'
      assert_guess :filename => 'zlogin'
      assert_guess :filename => 'zlogout'
      deny_guess   :filename => 'foo'
    end

    it 'guesses by mimetype' do
      assert_guess :mimetype => 'application/x-sh'
      assert_guess :mimetype => 'application/x-shellscript'
      assert_guess :mimetype => 'text/x-sh'
      assert_guess :mimetype => 'text/x-shellscript'
    end

    it 'guesses by source' do
      assert_guess :source => '#!/bin/bash'
      assert_guess :source => '   #!   /bin/bash'
      assert_guess :source => '#!/usr/bin/env bash'
      assert_guess :source => '#!/usr/bin/env bash -i'
      assert_guess :source => '#compdef myfunction1 mufunction2'
      assert_guess :source => '#autoload'
      assert_guess :source => '#autoload +X'
      deny_guess   :source => '#!/bin/smash'
      # not sure why you would do this, but hey, whatevs
      deny_guess   :source => '#!/bin/bash/python'
    end
  end
end