File: test_scanner.rb

package info (click to toggle)
ruby-journey 1.0.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 292 kB
  • sloc: ruby: 2,830; javascript: 113; yacc: 42; makefile: 2
file content (54 lines) | stat: -rw-r--r-- 1,665 bytes parent folder | download | duplicates (4)
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
require 'helper'

module Journey
  module Definition
    class TestScanner < MiniTest::Unit::TestCase
      def setup
        @scanner = Scanner.new
      end

      # /page/:id(/:action)(.:format)
      def test_tokens
        [
          ['/',      [[:SLASH, '/']]],
          ['*omg',   [[:STAR, '*'], [:LITERAL, 'omg']]],
          ['/page',  [[:SLASH, '/'], [:LITERAL, 'page']]],
          ['/~page', [[:SLASH, '/'], [:LITERAL, '~page']]],
          ['/pa-ge', [[:SLASH, '/'], [:LITERAL, 'pa-ge']]],
          ['/:page', [[:SLASH, '/'], [:SYMBOL, ':page']]],
          ['/(:page)', [
                        [:SLASH, '/'],
                        [:LPAREN, '('],
                        [:SYMBOL, ':page'],
                        [:RPAREN, ')'],
                      ]],
          ['(/:action)', [
                          [:LPAREN, '('],
                          [:SLASH, '/'],
                          [:SYMBOL, ':action'],
                          [:RPAREN, ')'],
                         ]],
          ['(())', [[:LPAREN, '('],
                   [:LPAREN, '('], [:RPAREN, ')'], [:RPAREN, ')']]],
          ['(.:format)', [
                          [:LPAREN, '('],
                          [:DOT, '.'],
                          [:SYMBOL, ':format'],
                          [:RPAREN, ')'],
                        ]],
        ].each do |str, expected|
          @scanner.scan_setup str
          assert_tokens expected, @scanner
        end
      end

      def assert_tokens tokens, scanner
        toks = []
        while tok = scanner.next_token
          toks << tok
        end
        assert_equal tokens, toks
      end
    end
  end
end