spec/unit/tokenizer_spec.rb in sql_tree-0.1.1 vs spec/unit/tokenizer_spec.rb in sql_tree-0.2.0

- old
+ new

@@ -1,6 +1,6 @@ -require "#{File.dirname(__FILE__)}/../spec_helper" +require 'spec_helper' describe SQLTree::Tokenizer do context "recognizing single tokens" do it "should tokenize SQL query keywords" do @@ -9,10 +9,14 @@ it "should tokenize expression keywords" do SQLTree::Tokenizer.tokenize('and').should tokenize_to(:and) end + it "should tokenize a begin SQL keyword" do + SQLTree::Tokenizer.tokenize('BEGIN').should tokenize_to(:begin) + end + it "should tokenize muliple separate keywords" do SQLTree::Tokenizer.tokenize('SELECT DISTINCT').should tokenize_to(:select, :distinct) end it "should ignore excessive whitespace" do @@ -56,10 +60,18 @@ end it "should tokenize commas" do SQLTree::Tokenizer.tokenize('a , "b"').should tokenize_to(sql_var('a'), comma, sql_var('b')) end + + it "should tokenize postgresql string escape token" do + SQLTree::Tokenizer.tokenize("E'foo'").should tokenize_to(:string_escape, "foo") + end + + it "should tokenize postgresql interval statements" do + SQLTree::Tokenizer.tokenize("interval '2 days'").should tokenize_to(:interval, "2 days") + end end # # Combined tokens are disabled for now; # # Combination is currently done in the parsing phase. # context "combining double keywords" do @@ -74,9 +86,13 @@ :select, sql_var('a'), dot, :multiply, :from, sql_var('a_table'), :as, sql_var('a'), :where, sql_var('a'), dot, sql_var('id'), :gt, 1) end it "should tokenize a function call" do SQLTree::Tokenizer.tokenize("MD5('test')").should tokenize_to(sql_var('MD5'), lparen, 'test', rparen) + end + + it "should tokenize a posgresql SET call" do + SQLTree::Tokenizer.tokenize("SET client_min_messages TO 'panic'").should tokenize_to(:set, sql_var('client_min_messages'), :to, 'panic') end end end