diff --git a/CHANGELOG b/CHANGELOG index e77a0a2..bcbaf89 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,48 @@ +v1.0.6 +------ + +* license file added + +v1.0.5 +------ + +* register .sh file extension with :bash scanner (by Alexandre Vezina) + +v1.0.4 +------ + +* fix issue #10 +* fix source + +v1.0.3 +------ + +* fix function closing bracket (by codez) +* fix # in string is not a comment (by codez) + + +v1.0.2 +------ + +* fix nested shells + + +v1.0.1 +------ + +* fix open single quote +* support for heredoc + + +v1.0 +---- + +* compatible with coderay 1.0 +* `` doesn't change state but sets @shell variable to true +* support for arrays +* fix comments + + v0.2.1 ------ diff --git a/MIT_License.txt b/MIT_License.txt new file mode 100644 index 0000000..8e15fb5 --- /dev/null +++ b/MIT_License.txt @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2010-2014 Petr Kovar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/README.md b/README.md index bf01a6a..246e276 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,27 @@ Bash scanner for highlighting scripts with CodeRay ================================================== -### Instalation +### Installation - gem install coderay_bash +```bash +gem install coderay_bash +``` ### Usage - require 'rubygems' - require 'coderay_bash' +```ruby +require 'rubygems' +require 'coderay_bash' - plain = File.read('some_script.sh') - @body = CodeRay.scan(plain, :bash).div +plain = File.read('some_script.sh') +@body = CodeRay.scan(plain, :bash).div +``` ### in your template then do something like - <%= @body %> +```html +<%= @body %> +``` ### Types @@ -23,3 +29,7 @@ Bash scanner for highlighting scripts with CodeRay * `:erb_bash` -- erb code in bash strings For more information see [CodeRay web pages](http://coderay.rubychan.de/) + +### Licence + +MIT diff --git a/Rakefile b/Rakefile index 2dab200..145cf1d 100644 --- a/Rakefile +++ b/Rakefile @@ -4,14 +4,14 @@ # @author: Petr Kovar $KCODE='UTF8' if RUBY_VERSION < "1.9" -require 'rake/gempackagetask' +require 'rubygems/package_task' require 'rake/testtask' require 'rake/clean' CLEAN << "coverage" << "pkg" << "README.html" << "CHANGELOG.html" task :default => [:test, :gem] -Rake::GemPackageTask.new(eval(File.read("coderay_bash.gemspec"))) {|pkg|} +Gem::PackageTask.new(eval(File.read("coderay_bash.gemspec"))) {|pkg|} Rake::TestTask.new(:test) do |t| t.pattern = File.join(File.dirname(__FILE__), 'test/test.rb') diff --git a/coderay_bash.gemspec b/coderay_bash.gemspec index 01aaf0c..1b32840 100644 --- a/coderay_bash.gemspec +++ b/coderay_bash.gemspec @@ -12,18 +12,19 @@ spec = Gem::Specification.new do |s| s.homepage = "http://github.com/pejuko/coderay_bash" s.email = "pejuko@gmail.com" s.authors = ["Petr Kovar"] + s.licenses = ["MIT"] s.name = 'coderay_bash' - s.version = '0.2.1' + s.version = '1.0.7' s.date = Time.now.strftime("%Y-%m-%d") - s.add_dependency('coderay', '< 1.0') + s.add_dependency('coderay', '>= 1.0') s.require_path = 'lib' - s.files = ["README.md", "coderay_bash.gemspec", "Rakefile"] + s.files = ["MIT_License.txt", "README.md", "CHANGELOG", "coderay_bash.gemspec", "Rakefile"] s.files += Dir["lib/**/*.rb"] s.post_install_message = <= 1.0. +Bash highlighting for coderay. This gem was tested with coderay 1.0 and won't work with coderay < 1.0. EOF end diff --git a/lib/coderay/scanners/bash.rb b/lib/coderay/scanners/bash.rb index 8d6f5d7..03783f8 100644 --- a/lib/coderay/scanners/bash.rb +++ b/lib/coderay/scanners/bash.rb @@ -1,7 +1,8 @@ # Scanner for Bash # Author: Petr Kovar -module CodeRay -module Scanners + +module CodeRay module Scanners + class Bash < Scanner register_for :bash @@ -22,6 +23,14 @@ class Bash < Scanner local logout printf read set shopt source type typeset ulimit unalias ) + PROGRAMS = %w( + awk bash bunzip2 bzcat bzip2 cat chgrp chmod chown cp cut date dd df dir dmesg du ed egrep + false fgrep findmnt fusermount gawk grep groups gunzip gzip hostname install keyctl kill less + ln loadkeys login ls lsblk lsinitcpio lsmod mbchk mkdir mkfifo mknod more mount mountpoint mv + netstat pidof ping ping6 ps pwd readlink red rm rmdir sed sh shred sleep stty su sudo sync tar + touch tput tr traceroute traceroute6 true umount uname uncompress vdir zcat + ) + VARIABLES = %w( CDPATH HOME IFS MAIL MAILPATH OPTARG OPTIND PATH PS1 PS2 ) @@ -46,8 +55,9 @@ class Bash < Scanner add(RESERVED_WORDS, :reserved). add(COMMANDS, :method). add(BASH_COMMANDS, :method). - add(VARIABLES, :pre_type). - add(BASH_VARIABLES, :pre_type) +# add(PROGRAMS, :method). + add(VARIABLES, :predefined). + add(BASH_VARIABLES, :predefined) attr_reader :state, :quote @@ -56,15 +66,17 @@ def initialize(*args) @state = :initial @quote = nil @shell = false + @brace_shell = 0 + @quote_brace_shell = 0 end - def scan_tokens tokens, options + def scan_tokens encoder, options until eos? kind = match = nil if match = scan(/\n/) - tokens << [match, :end_line] + encoder.text_token(match, :end_line) next end @@ -73,9 +85,11 @@ def scan_tokens tokens, options kind = :directive elsif match = scan(/\s*#.*/) kind = :comment - elsif match = scan(/.#/) + elsif match = scan(/[^"]#/) kind = :ident - elsif match = scan(/(?:\. |source ).*/) + elsif match = scan(/\.\.+/) + kind = :plain + elsif match = scan(/(?:\.|source)\s+/) kind = :reserved elsif match = scan(/(?:\\.|,)/) kind = :plain @@ -84,15 +98,27 @@ def scan_tokens tokens, options elsif match = scan(/"/) @state = :quote @quote = match - tokens << [:open, :string] - tokens << [match, :delimiter] + encoder.begin_group :string + encoder.text_token(match, :delimiter) + next + elsif match = scan(/<<\S+/) + @state = :quote + match =~ /<<(\S+)/ + @quote = "#{$1}" + encoder.begin_group :string + encoder.text_token(match, :delimiter) next elsif match = scan(/`/) - tokens << [@shell ? :close : :open, :shell] + if @shell + encoder.text_token(match, :delimiter) + encoder.end_group :shell + else + encoder.begin_group :shell + encoder.text_token(match, :delimiter) + end @shell = (not @shell) - tokens << [match, :delimiter] next - elsif match = scan(/'[^']*'/) + elsif match = scan(/'[^']*'?/) kind = :string elsif match = scan(/(?: \& | > | < | \| >> | << | >\& )/ox) kind = :bin @@ -107,13 +133,29 @@ def scan_tokens tokens, options kind = :global_variable elsif match = scan(/ \$\{ [^\}]+ \} /ox) match =~ /\$\{(.*)\}/ - kind = IDENT_KIND[$1] + var=$1 + if var =~ /\[.*\]/ + encoder.text_token("${", :instance_variable) + match_array(var, encoder) + encoder.text_token("}", :instance_variable) + next + end + kind = IDENT_KIND[var] kind = :instance_variable if kind == :ident - elsif match = scan(/ \$\( [^\)]+ \) /ox) - kind = :shell + #elsif match = scan(/ \$\( [^\)]+ \) /ox) + elsif match = scan(/ \$\( /ox) + @brace_shell += 1 + encoder.begin_group :shell + encoder.text_token(match, :delimiter) + next + elsif @brace_shell > 0 && match = scan(/ \) /ox) + encoder.text_token(match, :delimiter) + encoder.end_group :shell + @brace_shell -= 1 + next elsif match = scan(PRE_CONSTANTS) - kind = :pre_constant - elsif match = scan(/[^\s'"]*[A-Za-z_][A-Za-z_0-9]*\+?=/) + kind = :predefined_constant + elsif match = scan(/[^\s'"]*?[A-Za-z_][A-Za-z_0-9]*\+?=/) match =~ /(.*?)([A-Za-z_][A-Za-z_0-9]*)(\+?=)/ str = $1 pre = $2 @@ -122,23 +164,23 @@ def scan_tokens tokens, options if str.to_s.strip.empty? kind = IDENT_KIND[pre] kind = :instance_variable if kind == :ident - tokens << [pre, kind] - tokens << [op, :operator] + encoder.text_token(pre, kind) + encoder.text_token(op, :operator) next end - elsif match = scan(/[A-Za-z_]+\[[A-Za-z_\d]+\]/) + elsif match = scan(/[A-Za-z_]+\[[A-Za-z_\@\*\d]+\]/) # array - kind = IDENT_KIND(match) - kind = :instance_variable if kind == :ident + match_array(match, encoder) + next elsif match = scan(/ \$[A-Za-z_][A-Za-z_0-9]* /ox) match =~ /\$(.*)/ kind = IDENT_KIND[$1] kind = :instance_variable if kind == :ident elsif match = scan(/read \S+/) match =~ /read(\s+)(\S+)/ - tokens << ['read', :method] - tokens << [$1, :space] - tokens << [$2, :instance_variable] + encoder.text_token('read', :method) + encoder.text_token($1, :space) + encoder.text_token($2, :instance_variable) next elsif match = scan(/[\!\:\[\]\{\}]/) kind = :reserved @@ -146,8 +188,8 @@ def scan_tokens tokens, options match =~ /([^;]+);?/ kind = IDENT_KIND[$1] if match[/([^;]+);$/] - tokens << [$1, kind] - tokens << [';', :delimiter] + encoder.text_token($1, kind) + encoder.text_token(';', :delimiter) next end elsif match = scan(/(?: = | - | \+ | \{ | \} | \( | \) | && | \|\| | ;; | ! )/ox) @@ -164,20 +206,44 @@ def scan_tokens tokens, options if (match = scan(/\\.?/)) kind = :content elsif match = scan(/#{@quote}/) - tokens << [match, :delimiter] - tokens << [:close, :string] if @quote == '"' + encoder.text_token(match, :delimiter) + encoder.end_group :string @quote = nil @state = :initial next #kind = :symbol elsif match = scan(PRE_CONSTANTS) - kind = :pre_constant + kind = :predefined_constant elsif match = scan(/ (?: \$\(\(.*?\)\) ) /x) kind = :global_variable - elsif match = scan(/ \$\{?[A-Za-z_][A-Za-z_\d]*\}? /x) + elsif match = scan(/ \$\( /ox) + encoder.begin_group :shell + encoder.text_token(match, :delimiter) + @quote_brace_shell += 1 + next + elsif match = scan(/\)/) + if @quote_brace_shell > 0 + encoder.text_token(match, :delimiter) + encoder.end_group :shell + @quote_brace_shell -= 1 + next + else + kind = :content + end + elsif match = scan(/ \$ (?: (?: \{ [^\}]* \}) | (?: [A-Za-z_0-9]+ ) ) /x) + match =~ /(\$\{?)([^\}]*)(\}?)/ + pre=$1 + var=$2 + post=$3 + if var =~ /\[.*?\]/ + encoder.text_token(pre,:instance_variable) + match_array(var, encoder) + encoder.text_token(post,:instance_variable) + next + end kind = IDENT_KIND[match] kind = :instance_variable if kind == :ident - elsif match = scan(/[^#{@quote}\\]+/) + elsif match = scan(/[^\)\$#{@quote}\\]+/) kind = :content else match = scan(/.+/) # this shouldn't be @@ -188,12 +254,28 @@ def scan_tokens tokens, options end match ||= matched - tokens << [match, kind] + encoder.text_token(match, kind) + end + + if @state == :quote + encoder.end_group :string end - tokens + encoder end + + def match_array(match, encoder) + match =~ /(.+)\[(.*?)\]/ + var = $1 + key = $2 + kind = IDENT_KIND[var] + kind = :instance_variable if kind == :ident + encoder.text_token(var, kind) + encoder.text_token("[", :operator) + encoder.text_token(key, :key) + encoder.text_token("]", :operator) + end def handle_error(match, options) o = {:ignore_errors => true}.merge(options) diff --git a/lib/coderay/scanners/erb_bash.rb b/lib/coderay/scanners/erb_bash.rb index f3adefb..7e05eb2 100644 --- a/lib/coderay/scanners/erb_bash.rb +++ b/lib/coderay/scanners/erb_bash.rb @@ -1,10 +1,10 @@ # Scanner for Bash # Author: spam+github@codez.ch -require 'coderay/scanners/rhtml' +require 'coderay/scanners/erb' module CodeRay module Scanners - class ErbBash < RHTML + class ErbBash < ERB register_for :erb_bash protected diff --git a/lib/coderay_bash.rb b/lib/coderay_bash.rb index 85f515d..5c2d2c0 100644 --- a/lib/coderay_bash.rb +++ b/lib/coderay_bash.rb @@ -4,3 +4,6 @@ require File.join(path, "coderay/scanners/bash.rb") require File.join(path, "coderay/scanners/erb_bash.rb") + +# Register file types +::CodeRay::FileType::TypeFromExt['sh'] = :bash diff --git a/test/function.sh b/test/function.sh new file mode 100644 index 0000000..f719615 --- /dev/null +++ b/test/function.sh @@ -0,0 +1,6 @@ +#/bin/bash + +function bla() +{ + other_command +} \ No newline at end of file diff --git a/test/heredoc.sh b/test/heredoc.sh new file mode 100644 index 0000000..782a1cd --- /dev/null +++ b/test/heredoc.sh @@ -0,0 +1,7 @@ +#/bin/bash + +cat < foo +echo "more" >> foo # so this is a comment now diff --git a/test/test.rb b/test/test.rb index a790a18..3b4e706 100644 --- a/test/test.rb +++ b/test/test.rb @@ -10,112 +10,90 @@ $current_dir = File.expand_path(File.dirname(__FILE__)) $:.unshift File.expand_path(File.join($current_dir, "..")) -gem "coderay", "<1.0" require 'lib/coderay_bash' + class TestErbBash < Test::Unit::TestCase + def test_0010_ErbBash eb_file = File.join($current_dir, "erb_bash.sh") assert_equal( - [["#!/bin/sh", :directive], - ["\n", :end_line], - ["\n", :end_line], - ["perl", :ident], - [" ", :space], - ["-", :operator], - ["e", :ident], - ["'s/to=5/to=10/'", :string], - [" ", :space], - ["/", :plain], - ["test", :method], - ["/", :plain], - ["file", :ident], - ["\n", :end_line], - ["echo", :method], - [" ", :space], - [:open, :string], - ["\"", :delimiter], - ["Parsed at ", :content], - [:open, :inline], - ["<%=", :inline_delimiter], - [" ", :space], - ["Time", :constant], - [".", :operator], - ["now", :ident], - [" ", :space], - ["%>", :inline_delimiter], - [:close, :inline], - ["\"", :delimiter], - [:close, :string], - ["\n", :end_line], - ["echo", :method], - [" ", :space], - [:open, :string], - ["\"", :delimiter], - ["Executed at `Date`", :content], - ["\"", :delimiter], - [:close, :string], - ["\n", :end_line], - ["command", :method], - [" ", :space], - [">>>>>'open quote<<<<<", :error], - ["\n", :end_line], - ["other_command", :ident], - ["\n", :end_line] - ], - CodeRay.scan(File.read(eb_file), :erb_bash, :ignore_errors => false)) + #["#!/bin/sh", :directive, "\n", :end_line, "\n", :end_line, "perl", :ident, " ", :space, "-", :operator, "e", :ident, "'s/to=5/to=10/'", :string, " ", :space, "/", :plain, "test", :method, "/", :plain, "file", :ident, "\n", :end_line, "echo", :method, " ", :space, :begin_group, :string, "\"", :delimiter, "Parsed at ", :content, :begin_group, :inline, "<%=", :inline_delimiter, " ", :space, "Time", :constant, ".", :operator, "now", :ident, " ", :space, "%>", :inline_delimiter, :end_group, :inline, "\"", :delimiter, :end_group, :string, "\n", :end_line, "echo", :method, " ", :space, :begin_group, :string, "\"", :delimiter, "Executed at `Date`", :content, "\"", :delimiter, :end_group, :string, "\n", :end_line, "command", :method, " ", :space, ">>>>>'open quote<<<<<", :error, "\n", :end_line, "other_command", :ident, "\n", :end_line], + ["#!/bin/sh", :directive, "\n", :end_line, "\n", :end_line, "perl", :ident, " ", :space, "-", :operator, "e", :ident, "'s/to=5/to=10/'", :string, " ", :space, "/", :plain, "test", :method, "/", :plain, "file", :ident, "\n", :end_line, "echo", :method, " ", :space, :begin_group, :string, "\"", :delimiter, "Parsed at ", :content, :end_group, :string, :begin_group, :inline, "<%=", :inline_delimiter, " ", :space, "Time", :constant, ".", :operator, "now", :ident, " ", :space, "%>", :inline_delimiter, :end_group, :inline, "\"", :delimiter, :end_group, :string, "\n", :end_line, "echo", :method, " ", :space, :begin_group, :string, "\"", :delimiter, "Executed at `Date`", :content, "\"", :delimiter, :end_group, :string, "\n", :end_line, "command", :method, " ", :space, "'open quote\nother_command\n", :string], + CodeRay.scan(File.read(eb_file), :erb_bash, :ignore_errors => false).tokens + ) end - def test_0011_ErbBash_Ignoring_Errors + def test_0020_ErbBash_Ignoring_Errors eb_file = File.join($current_dir, "erb_bash.sh") - assert_equal( - [["#!/bin/sh", :directive], - ["\n", :end_line], - ["\n", :end_line], - ["perl", :ident], - [" ", :space], - ["-", :operator], - ["e", :ident], - ["'s/to=5/to=10/'", :string], - [" ", :space], - ["/", :plain], - ["test", :method], - ["/", :plain], - ["file", :ident], - ["\n", :end_line], - ["echo", :method], - [" ", :space], - [:open, :string], - ["\"", :delimiter], - ["Parsed at ", :content], - [:open, :inline], - ["<%=", :inline_delimiter], - [" ", :space], - ["Time", :constant], - [".", :operator], - ["now", :ident], - [" ", :space], - ["%>", :inline_delimiter], - [:close, :inline], - ["\"", :delimiter], - [:close, :string], - ["\n", :end_line], - ["echo", :method], - [" ", :space], - [:open, :string], - ["\"", :delimiter], - ["Executed at `Date`", :content], - ["\"", :delimiter], - [:close, :string], - ["\n", :end_line], - ["command", :method], - [" ", :space], - ["'open quote", :plain], - ["\n", :end_line], - ["other_command", :ident], - ["\n", :end_line] - ], - CodeRay.scan(File.read(eb_file), :erb_bash)) + assert_equal( + #["#!/bin/sh", :directive, "\n", :end_line, "\n", :end_line, "perl", :ident, " ", :space, "-", :operator, "e", :ident, "'s/to=5/to=10/'", :string, " ", :space, "/", :plain, "test", :method, "/", :plain, "file", :ident, "\n", :end_line, "echo", :method, " ", :space, :begin_group, :string, "\"", :delimiter, "Parsed at ", :content, :begin_group, :inline, "<%=", :inline_delimiter, " ", :space, "Time", :constant, ".", :operator, "now", :ident, " ", :space, "%>", :inline_delimiter, :end_group, :inline, "\"", :delimiter, :end_group, :string, "\n", :end_line, "echo", :method, " ", :space, :begin_group, :string, "\"", :delimiter, "Executed at `Date`", :content, "\"", :delimiter, :end_group, :string, "\n", :end_line, "command", :method, " ", :space, "'open quote", :plain, "\n", :end_line, "other_command", :ident, "\n", :end_line], + ["#!/bin/sh", :directive, "\n", :end_line, "\n", :end_line, "perl", :ident, " ", :space, "-", :operator, "e", :ident, "'s/to=5/to=10/'", :string, " ", :space, "/", :plain, "test", :method, "/", :plain, "file", :ident, "\n", :end_line, "echo", :method, " ", :space, :begin_group, :string, "\"", :delimiter, "Parsed at ", :content, :end_group, :string, :begin_group, :inline, "<%=", :inline_delimiter, " ", :space, "Time", :constant, ".", :operator, "now", :ident, " ", :space, "%>", :inline_delimiter, :end_group, :inline, "\"", :delimiter, :end_group, :string, "\n", :end_line, "echo", :method, " ", :space, :begin_group, :string, "\"", :delimiter, "Executed at `Date`", :content, "\"", :delimiter, :end_group, :string, "\n", :end_line, "command", :method, " ", :space, "'open quote\nother_command\n", :string], + CodeRay.scan(File.read(eb_file), :erb_bash).tokens + ) + end + + def test_0030_ErbBash_to_html + eb_file = File.join($current_dir, "function.sh") + assert_nothing_raised { + CodeRay.scan(File.read(eb_file), :erb_bash, :ignore_errors => false).html + } + end + +end + + +class TestString < Test::Unit::TestCase + + def test_0010_heredoc + file = File.join($current_dir, "heredoc.sh") + assert_equal( + ["#/bin/bash", :comment, "\n", :end_line, "\n", :end_line, "cat", :ident, " ", :space, :begin_group, :string, "<", :bin, " ", :space, "foo", :ident, "\n", :end_line, "echo", :method, " ", :space, :begin_group, :string, "\"", :delimiter, "more", :content, "\"", :delimiter, :end_group, :string, " ", :space, ">", :bin, ">", :bin, " ", :space, "foo", :ident, " # so this is a comment now", :comment, "\n", :end_line], + CodeRay.scan(File.read(eb_file), :bash).tokens + ) + end + +end + + +class TestNested < Test::Unit::TestCase + + def test_0010_nested_shell + file = File.join($current_dir, "nested_shells.sh") + assert_equal( + ["blueberry", :instance_variable, "=", :operator, :begin_group, :shell, "$(", :delimiter, "date", :ident, " ", :space, "-", :operator, "d", :ident, " ", :space, :begin_group, :string, "\"", :delimiter, :begin_group, :shell, "$(", :delimiter, "stat -c ", :content, :begin_group, :shell, "$(", :delimiter, "%z", :content, ")", :delimiter, :end_group, :shell, " blueberry.exe", :content, ")", :delimiter, :end_group, :shell, "\"", :delimiter, :end_group, :string, ")", :delimiter, :end_group, :shell, "\n", :end_line], + CodeRay.scan(File.read(file), :bash).tokens + ) + end + +end + + +class TestArray < Test::Unit::TestCase + + def test_0010_Array + eb_file = File.join($current_dir, "json.sh") + assert_equal(["cat",:ident," ",:space,"$1",:predefined_constant," ",:space,"|",:plain," ",:space,"while",:reserved," ",:space,"read",:method," ",:space,"json;",:instance_variable," ",:space,"do",:reserved," ",:space,"if",:reserved," ",:space,"[",:reserved,"[",:reserved," ",:space,"${",:instance_variable,"array2",:instance_variable,"[",:operator,"0",:key,"]",:operator,"}",:instance_variable," ",:space,"=",:operator,"=",:operator," ",:space,"1",:integer," ",:space,"]",:reserved,"]",:reserved,";",:delimiter," ",:space,"then",:reserved,"\n",:end_line,"echo",:method," ",:space,"$json",:instance_variable," ",:space,"|",:plain," ",:space,"......",:plain,"\n",:end_line], + CodeRay.scan(File.read(eb_file), :bash).tokens) + end + +end + + +class TestKeepPath < Test::Unit::TestCase + + def test_0010_Array + file = File.join($current_dir, "keep_path.sh") + assert_equal(["#!/bin/sh", :directive, "\n", :end_line, "\n", :end_line, "sudo", :ident, " ", :space, "qemu", :ident, "-", :operator, "kvm", :ident, " ", :space, "-", :operator, "m", :ident, " ", :space, "768", :integer, " ", :space, "\\", :plain, "\n", :end_line, " ", :space, "-", :operator, "boot", :ident, " ", :space, "d", :ident, " ", :space, "\\", :plain, "\n", :end_line, " ", :space, "-", :operator, "drive", :ident, " ", :space, "file", :instance_variable, "=", :operator, "/bak/kvm/salix.qcow,cache=", :plain, "writeback", :ident, " ", :space, "\\", :plain, "\n", :end_line, " ", :space, "-", :operator, "cdrom", :ident, " ", :space, "/", :plain, "ntfs", :ident, "-", :operator, "d", :ident, "/", :plain, "ISO", :ident, "/", :plain, "salix64", :ident, "-", :operator, "openbox", :ident, "-", :operator, "14.1.", :float, "iso", :ident, " ", :space, "-", :operator, "vnc", :ident, " ", :space, ":", :reserved, "3", :integer, "\n", :end_line, "\n", :end_line], + CodeRay.scan(File.read(file), :bash).tokens) end end