aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2012-06-20 17:16:53 -0500
committerJoshua Peek <josh@joshpeek.com>2012-06-20 17:16:53 -0500
commit5cdd5e206c2e8751c36d84b6f08673e79bb16cfb (patch)
tree807bd0b5c0156ac3664b4e3c8bb994cda8e0ac10 /test
parentc353d3a0500754093afec4bd451e5a52174b4926 (diff)
Improve operator tokenizing
Diffstat (limited to 'test')
-rw-r--r--test/test_tokenizer.rb18
1 files changed, 16 insertions, 2 deletions
diff --git a/test/test_tokenizer.rb b/test/test_tokenizer.rb
index cea4e53..d38562c 100644
--- a/test/test_tokenizer.rb
+++ b/test/test_tokenizer.rb
@@ -25,6 +25,7 @@ class TestTokenizer < Test::Unit::TestCase
def test_skip_number_literals
assert_equal %w(+), tokenize('1 + 1')
assert_equal %w(add \( \)), tokenize('add(123, 456)')
+ assert_equal %w(|), tokenize('0x01 | 0x10')
end
def test_skip_comments
@@ -47,20 +48,33 @@ class TestTokenizer < Test::Unit::TestCase
assert_equal %w(<?xml> version=), tokenize("<?xml version=\"1.0\"?>")
end
+ def test_operators
+ assert_equal %w(+), tokenize("1 + 1")
+ assert_equal %w(-), tokenize("1 - 1")
+ assert_equal %w(*), tokenize("1 * 1")
+ assert_equal %w(/), tokenize("1 / 1")
+ assert_equal %w(&), tokenize("1 & 1")
+ assert_equal %w(&&), tokenize("1 && 1")
+ assert_equal %w(|), tokenize("1 | 1")
+ assert_equal %w(||), tokenize("1 || 1")
+ assert_equal %w(<), tokenize("1 < 0x01")
+ assert_equal %w(<<), tokenize("1 << 0x01")
+ end
+
def test_c_tokens
assert_equal %w(#ifndef HELLO_H #define HELLO_H void hello \( \) ; #endif), tokenize(:"c/hello.h")
assert_equal %w(#include <stdio.h> int main \( \) { printf \( \) ; return ; }), tokenize(:"c/hello.c")
end
def test_cpp_tokens
- assert_equal %w(class Bar { protected char name ; public void hello \( \) ; }), tokenize(:"cpp/bar.h")
+ assert_equal %w(class Bar { protected char *name ; public void hello \( \) ; }), tokenize(:"cpp/bar.h")
assert_equal %w(#include <iostream> using namespace std ; int main \( \) { cout << << endl ; }), tokenize(:"cpp/hello.cpp")
end
def test_objective_c_tokens
assert_equal %w(#import <Foundation/Foundation.h> @interface Foo NSObject { } @end), tokenize(:"objective-c/Foo.h")
assert_equal %w(#import @implementation Foo @end), tokenize(:"objective-c/Foo.m")
- assert_equal %w(#import <Cocoa/Cocoa.h> int main \( int argc char argv \) { NSLog \( @ \) ; return ; }), tokenize(:"objective-c/hello.m")
+ assert_equal %w(#import <Cocoa/Cocoa.h> int main \( int argc char *argv \) { NSLog \( @ \) ; return ; }), tokenize(:"objective-c/hello.m")
end
def test_javascript_tokens