From a3bb8683fbb7fbcff0459ca1652492b51d01c027 Mon Sep 17 00:00:00 2001 From: sonota88 Date: Fri, 30 Mar 2018 19:29:00 +0900 Subject: [PATCH 1/6] Initialize encounter_between in format_list_main_loop() Some supports for PR #7. --- lib/anbt-sql-formatter/formatter.rb | 4 +++- test/test_formatter.rb | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/anbt-sql-formatter/formatter.rb b/lib/anbt-sql-formatter/formatter.rb index 1aa6357..f9de279 100644 --- a/lib/anbt-sql-formatter/formatter.rb +++ b/lib/anbt-sql-formatter/formatter.rb @@ -56,7 +56,7 @@ def format(sql_str) tokens = @parser.parse(sql_str) statements = split_to_statements(tokens) - + statements = statements.map{|inner_tokens| format_list(inner_tokens) } @@ -175,6 +175,8 @@ def format_list_main_loop(tokens) prev = AnbtSql::Token.new(AnbtSql::TokenConstants::SPACE, " ") + encounter_between = false + index = 0 # Length of tokens changes in loop! while index < tokens.size diff --git a/test/test_formatter.rb b/test/test_formatter.rb index 0e3f0b7..9cc0034 100644 --- a/test/test_formatter.rb +++ b/test/test_formatter.rb @@ -498,8 +498,20 @@ def test_format @fmt.format("a;") ) end - - + + def test_format_between + assert_equals( + "should not add a new line to 'BETWEEN ... AND ...'", + strip_indent( + <<-EOB + BETWEEN 0 AND 1 + EOB + ), + @fmt.format("between 0 and 1") + ) + end + + def test_split_to_statements msg = "split_to_statements - " From 4e07290565072b414f46fd358524afae14431a63 Mon Sep 17 00:00:00 2001 From: sonota88 Date: Tue, 6 Mar 2018 06:50:32 +0900 Subject: [PATCH 2/6] chore: Ignore Emacs backup file --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 4040c6c..d5f329d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ .bundle Gemfile.lock pkg/* + +# Emacs +*~ From 62ceba5142c2a83a8e47cc28c1f35215b091c6f7 Mon Sep 17 00:00:00 2001 From: sonota88 Date: Fri, 2 Feb 2018 07:51:15 +0900 Subject: [PATCH 3/6] refactor: Separate test methods --- test/test_coarse-tokenizer.rb | 84 ++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 6 deletions(-) diff --git a/test/test_coarse-tokenizer.rb b/test/test_coarse-tokenizer.rb index 5b34282..4495192 100644 --- a/test/test_coarse-tokenizer.rb +++ b/test/test_coarse-tokenizer.rb @@ -61,7 +61,7 @@ def test_shift_token end - def test_tokenize + def test_tokenize_1 msg = "tokenize - " assert_equals( @@ -77,6 +77,10 @@ def test_tokenize EOB ))) ) + end + + def test_tokenize_2 + msg = "tokenize - " ######## assert_equals( @@ -93,6 +97,10 @@ def test_tokenize EOB ))) ) + end + + def test_tokenize_3 + msg = "tokenize - " ######## assert_equals( @@ -109,6 +117,10 @@ def test_tokenize EOB ))) ) + end + + def test_tokenize_4 + msg = "tokenize - " ######## assert_equals( @@ -127,6 +139,10 @@ def test_tokenize EOB ))) ) + end + + def test_tokenize_5 + msg = "tokenize - " ######## assert_equals( @@ -144,6 +160,10 @@ def test_tokenize EOB ))) ) + end + + def test_tokenize_6 + msg = "tokenize - " ######## assert_equals( @@ -163,7 +183,7 @@ def test_tokenize end - def test_string_in_string + def test_string_in_string_1 msg = "string_in_string" ######## @@ -180,6 +200,10 @@ def test_string_in_string EOB ))) ) + end + + def test_string_in_string_2 + msg = "string_in_string" ######## assert_equals( @@ -198,7 +222,7 @@ def test_string_in_string end - def test_comment_in_comment + def test_comment_in_comment_1 msg = "comment_in_comment - " ######## @@ -215,6 +239,10 @@ def test_comment_in_comment EOB ))) ) + end + + def test_comment_in_comment_2 + msg = "comment_in_comment - " ######## assert_equals( @@ -230,6 +258,10 @@ def test_comment_in_comment EOB ))) ) + end + + def test_comment_in_comment_3 + msg = "comment_in_comment - " ######## assert_equals( @@ -245,6 +277,10 @@ def test_comment_in_comment EOB ))) ) + end + + def test_comment_in_comment_4 + msg = "comment_in_comment - " ######## assert_equals( @@ -263,7 +299,7 @@ def test_comment_in_comment end - def test_string_in_comment + def test_string_in_comment_1 msg = "string_in_comment - " ######## @@ -280,6 +316,10 @@ def test_string_in_comment EOB ))) ) + end + + def test_string_in_comment_2 + msg = "string_in_comment - " ######## assert_equals( @@ -295,6 +335,10 @@ def test_string_in_comment EOB ))) ) + end + + def test_string_in_comment_3 + msg = "string_in_comment - " ######## assert_equals( @@ -310,6 +354,10 @@ def test_string_in_comment EOB ))) ) + end + + def test_string_in_comment_4 + msg = "string_in_comment - " ######## assert_equals( @@ -328,7 +376,7 @@ def test_string_in_comment end - def test_comment_in_string + def test_comment_in_string_1 msg = "comment_in_string - " ######## @@ -345,6 +393,10 @@ def test_comment_in_string EOB ))) ) + end + + def test_comment_in_string_2 + msg = "comment_in_string - " ######## assert_equals( @@ -360,6 +412,10 @@ def test_comment_in_string EOB ))) ) + end + + def test_comment_in_string_3 + msg = "comment_in_string - " ######## assert_equals( @@ -375,6 +431,10 @@ def test_comment_in_string EOB ))) ) + end + + def test_comment_in_string_4 + msg = "comment_in_string - " ######## assert_equals( @@ -393,7 +453,7 @@ def test_comment_in_string end - def test_string_escape + def test_string_escape_1 msg = "string_escape" ######## @@ -410,6 +470,10 @@ def test_string_escape EOB ))) ) + end + + def test_string_escape_2 + msg = "string_escape" ######## assert_equals( @@ -425,6 +489,10 @@ def test_string_escape EOB ))) ) + end + + def test_string_escape_3 + msg = "string_escape" ######## assert_equals( @@ -440,6 +508,10 @@ def test_string_escape EOB ))) ) + end + + def test_string_escape_4 + msg = "string_escape" ######## assert_equals( From 7c06429738dce4f536644fecad64efe27e3824d2 Mon Sep 17 00:00:00 2001 From: sonota88 Date: Sun, 4 Mar 2018 04:55:35 +0900 Subject: [PATCH 4/6] chore: Remove unnecessary separator comments --- test/test_coarse-tokenizer.rb | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/test/test_coarse-tokenizer.rb b/test/test_coarse-tokenizer.rb index 4495192..71523dd 100644 --- a/test/test_coarse-tokenizer.rb +++ b/test/test_coarse-tokenizer.rb @@ -82,7 +82,6 @@ def test_tokenize_1 def test_tokenize_2 msg = "tokenize - " - ######## assert_equals( msg, strip_indent( @@ -102,7 +101,6 @@ def test_tokenize_2 def test_tokenize_3 msg = "tokenize - " - ######## assert_equals( msg, strip_indent( @@ -122,7 +120,6 @@ def test_tokenize_3 def test_tokenize_4 msg = "tokenize - " - ######## assert_equals( msg, strip_indent( @@ -144,7 +141,6 @@ def test_tokenize_4 def test_tokenize_5 msg = "tokenize - " - ######## assert_equals( msg, strip_indent( @@ -165,7 +161,6 @@ def test_tokenize_5 def test_tokenize_6 msg = "tokenize - " - ######## assert_equals( msg + "begin with multiline comment", strip_indent( @@ -186,7 +181,6 @@ def test_tokenize_6 def test_string_in_string_1 msg = "string_in_string" - ######## assert_equals( msg, strip_indent( @@ -205,7 +199,6 @@ def test_string_in_string_1 def test_string_in_string_2 msg = "string_in_string" - ######## assert_equals( msg, strip_indent( @@ -225,7 +218,6 @@ def test_string_in_string_2 def test_comment_in_comment_1 msg = "comment_in_comment - " - ######## assert_equals( msg, strip_indent( @@ -244,7 +236,6 @@ def test_comment_in_comment_1 def test_comment_in_comment_2 msg = "comment_in_comment - " - ######## assert_equals( msg, strip_indent( @@ -263,7 +254,6 @@ def test_comment_in_comment_2 def test_comment_in_comment_3 msg = "comment_in_comment - " - ######## assert_equals( msg, strip_indent( @@ -282,7 +272,6 @@ def test_comment_in_comment_3 def test_comment_in_comment_4 msg = "comment_in_comment - " - ######## assert_equals( msg, strip_indent( @@ -302,7 +291,6 @@ def test_comment_in_comment_4 def test_string_in_comment_1 msg = "string_in_comment - " - ######## assert_equals( msg, strip_indent( @@ -321,7 +309,6 @@ def test_string_in_comment_1 def test_string_in_comment_2 msg = "string_in_comment - " - ######## assert_equals( msg, strip_indent( @@ -340,7 +327,6 @@ def test_string_in_comment_2 def test_string_in_comment_3 msg = "string_in_comment - " - ######## assert_equals( msg, strip_indent( @@ -359,7 +345,6 @@ def test_string_in_comment_3 def test_string_in_comment_4 msg = "string_in_comment - " - ######## assert_equals( msg, strip_indent( @@ -379,7 +364,6 @@ def test_string_in_comment_4 def test_comment_in_string_1 msg = "comment_in_string - " - ######## assert_equals( msg + "comment_single in quote_single", strip_indent( @@ -398,7 +382,6 @@ def test_comment_in_string_1 def test_comment_in_string_2 msg = "comment_in_string - " - ######## assert_equals( msg + "comment_single in quote_double", strip_indent( @@ -417,7 +400,6 @@ def test_comment_in_string_2 def test_comment_in_string_3 msg = "comment_in_string - " - ######## assert_equals( msg + "comment_multi in quote_double", strip_indent( @@ -436,7 +418,6 @@ def test_comment_in_string_3 def test_comment_in_string_4 msg = "comment_in_string - " - ######## assert_equals( msg + "comment_multi in quote_double", strip_indent( @@ -456,7 +437,6 @@ def test_comment_in_string_4 def test_string_escape_1 msg = "string_escape" - ######## assert_equals( msg, strip_indent( @@ -475,7 +455,6 @@ def test_string_escape_1 def test_string_escape_2 msg = "string_escape" - ######## assert_equals( msg, strip_indent( @@ -494,7 +473,6 @@ def test_string_escape_2 def test_string_escape_3 msg = "string_escape" - ######## assert_equals( msg, strip_indent( @@ -513,7 +491,6 @@ def test_string_escape_3 def test_string_escape_4 msg = "string_escape" - ######## assert_equals( msg, strip_indent( From 1dd3a34dc0f9b7e67279ae519deda792657faf64 Mon Sep 17 00:00:00 2001 From: sonota88 Date: Sun, 4 Mar 2018 05:09:42 +0900 Subject: [PATCH 5/6] refactor: Remove temporary variables 'msg' --- test/test_coarse-tokenizer.rb | 96 +++++++++-------------------------- 1 file changed, 24 insertions(+), 72 deletions(-) diff --git a/test/test_coarse-tokenizer.rb b/test/test_coarse-tokenizer.rb index 71523dd..84afc0d 100644 --- a/test/test_coarse-tokenizer.rb +++ b/test/test_coarse-tokenizer.rb @@ -62,10 +62,8 @@ def test_shift_token def test_tokenize_1 - msg = "tokenize - " - assert_equals( - msg, + "tokenize 1", strip_indent( <<-EOB plain (aa) @@ -80,10 +78,8 @@ def test_tokenize_1 end def test_tokenize_2 - msg = "tokenize - " - assert_equals( - msg, + "tokenize 2", strip_indent( <<-EOB plain (aa ) @@ -99,10 +95,8 @@ def test_tokenize_2 end def test_tokenize_3 - msg = "tokenize - " - assert_equals( - msg, + "tokenize 3", strip_indent( <<-EOB plain (aa ) @@ -118,10 +112,8 @@ def test_tokenize_3 end def test_tokenize_4 - msg = "tokenize - " - assert_equals( - msg, + "tokenize 4", strip_indent( <<-EOB plain (aa ) @@ -139,10 +131,8 @@ def test_tokenize_4 end def test_tokenize_5 - msg = "tokenize - " - assert_equals( - msg, + "tokenize 5", strip_indent( <<-EOB plain (aa ) @@ -159,10 +149,8 @@ def test_tokenize_5 end def test_tokenize_6 - msg = "tokenize - " - assert_equals( - msg + "begin with multiline comment", + "tokenize - begin with multiline comment", strip_indent( <<-EOB comment_multi (/* bb */) @@ -179,10 +167,8 @@ def test_tokenize_6 def test_string_in_string_1 - msg = "string_in_string" - assert_equals( - msg, + "string_in_string 1", strip_indent( <<-EOB quote_double ("aa'bb'cc") @@ -197,10 +183,8 @@ def test_string_in_string_1 end def test_string_in_string_2 - msg = "string_in_string" - assert_equals( - msg, + "string_in_string 2", strip_indent( <<-EOB quote_single ('aa"bb"cc') @@ -216,10 +200,8 @@ def test_string_in_string_2 def test_comment_in_comment_1 - msg = "comment_in_comment - " - assert_equals( - msg, + "comment_in_comment 1", strip_indent( <<-EOB comment_single (--a--b) @@ -234,10 +216,8 @@ def test_comment_in_comment_1 end def test_comment_in_comment_2 - msg = "comment_in_comment - " - assert_equals( - msg, + "comment_in_comment 2", strip_indent( <<-EOB comment_single (-- aa /* bb */) @@ -252,10 +232,8 @@ def test_comment_in_comment_2 end def test_comment_in_comment_3 - msg = "comment_in_comment - " - assert_equals( - msg, + "comment_in_comment 3", strip_indent( <<-EOB comment_multi (/* aa /* bb */) @@ -270,10 +248,8 @@ def test_comment_in_comment_3 end def test_comment_in_comment_4 - msg = "comment_in_comment - " - assert_equals( - msg, + "comment_in_comment 4", strip_indent( <<-EOB comment_multi (/* aa -- bb */) @@ -289,10 +265,8 @@ def test_comment_in_comment_4 def test_string_in_comment_1 - msg = "string_in_comment - " - assert_equals( - msg, + "string_in_comment 1", strip_indent( <<-EOB comment_single (-- aa "bb" cc) @@ -307,10 +281,8 @@ def test_string_in_comment_1 end def test_string_in_comment_2 - msg = "string_in_comment - " - assert_equals( - msg, + "string_in_comment 2", strip_indent( <<-EOB comment_single (-- aa 'bb' cc) @@ -325,10 +297,8 @@ def test_string_in_comment_2 end def test_string_in_comment_3 - msg = "string_in_comment - " - assert_equals( - msg, + "string_in_comment 3", strip_indent( <<-EOB comment_multi (/* aa "bb" cc */) @@ -343,10 +313,8 @@ def test_string_in_comment_3 end def test_string_in_comment_4 - msg = "string_in_comment - " - assert_equals( - msg, + "string_in_comment 4", strip_indent( <<-EOB comment_multi (/* aa 'bb' cc */) @@ -362,10 +330,8 @@ def test_string_in_comment_4 def test_comment_in_string_1 - msg = "comment_in_string - " - assert_equals( - msg + "comment_single in quote_single", + "comment_in_string - comment_single in quote_single", strip_indent( <<-EOB quote_single ('aa--bb') @@ -380,10 +346,8 @@ def test_comment_in_string_1 end def test_comment_in_string_2 - msg = "comment_in_string - " - assert_equals( - msg + "comment_single in quote_double", + "comment_in_string - comment_single in quote_double", strip_indent( <<-EOB quote_double ("aa--bb") @@ -398,10 +362,8 @@ def test_comment_in_string_2 end def test_comment_in_string_3 - msg = "comment_in_string - " - assert_equals( - msg + "comment_multi in quote_double", + "comment_in_string - comment_multi in quote_double", strip_indent( <<-EOB quote_double ("aa /* bb */ cc") @@ -416,10 +378,8 @@ def test_comment_in_string_3 end def test_comment_in_string_4 - msg = "comment_in_string - " - assert_equals( - msg + "comment_multi in quote_double", + "comment_in_string - comment_multi in quote_double", strip_indent( <<-EOB quote_single ('aa /* bb */ cc') @@ -435,10 +395,8 @@ def test_comment_in_string_4 def test_string_escape_1 - msg = "string_escape" - assert_equals( - msg, + "string_escape 1", strip_indent( <<-EOB quote_double ("_a_\\\\_b_\n_c_\\'_d_") @@ -453,10 +411,8 @@ def test_string_escape_1 end def test_string_escape_2 - msg = "string_escape" - assert_equals( - msg, + "string_escape 2", strip_indent( <<-EOB quote_single ('_a_\\\\_b_\n_c_\\'_d_') @@ -471,10 +427,8 @@ def test_string_escape_2 end def test_string_escape_3 - msg = "string_escape" - assert_equals( - msg, + "string_escape 3", strip_indent( <<-EOB quote_double ("_a_""_b_") @@ -489,10 +443,8 @@ def test_string_escape_3 end def test_string_escape_4 - msg = "string_escape" - assert_equals( - msg, + "string_escape 4", strip_indent( <<-EOB quote_single ('_a_''_b_') From 883ebd498c7f6a2035eb01de3cb01187beee4e09 Mon Sep 17 00:00:00 2001 From: sonota88 Date: Sat, 31 Mar 2018 10:07:58 +0900 Subject: [PATCH 6/6] Bump version to 0.0.6 --- CHANGELOG.md | 5 +++++ lib/anbt-sql-formatter/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 853d498..d655b8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 0.0.6 (2018-03-31) + +No breaking changes. + + # 0.0.5 (2016-11-29) No breaking changes. diff --git a/lib/anbt-sql-formatter/version.rb b/lib/anbt-sql-formatter/version.rb index d476836..d75eba9 100644 --- a/lib/anbt-sql-formatter/version.rb +++ b/lib/anbt-sql-formatter/version.rb @@ -1,7 +1,7 @@ module Anbt module Sql module Formatter - VERSION = "0.0.5" + VERSION = "0.0.6" end end end