Skip to content

Commit

Permalink
Merge pull request #8 from sonota88/develop_0.0.6
Browse files Browse the repository at this point in the history
version 0.0.6
  • Loading branch information
sonota88 authored Mar 31, 2018
2 parents 19ea8d1 + 883ebd4 commit d97bc81
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
.bundle
Gemfile.lock
pkg/*

# Emacs
*~
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.0.6 (2018-03-31)

No breaking changes.


# 0.0.5 (2016-11-29)

No breaking changes.
Expand Down
4 changes: 3 additions & 1 deletion lib/anbt-sql-formatter/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/anbt-sql-formatter/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Anbt
module Sql
module Formatter
VERSION = "0.0.5"
VERSION = "0.0.6"
end
end
end
133 changes: 67 additions & 66 deletions test/test_coarse-tokenizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ def test_shift_token
end


def test_tokenize
msg = "tokenize - "

def test_tokenize_1
assert_equals(
msg,
"tokenize 1",
strip_indent(
<<-EOB
plain (aa)
Expand All @@ -77,10 +75,11 @@ def test_tokenize
EOB
)))
)

########
end

def test_tokenize_2
assert_equals(
msg,
"tokenize 2",
strip_indent(
<<-EOB
plain (aa )
Expand All @@ -93,10 +92,11 @@ def test_tokenize
EOB
)))
)
end

########
def test_tokenize_3
assert_equals(
msg,
"tokenize 3",
strip_indent(
<<-EOB
plain (aa )
Expand All @@ -109,10 +109,11 @@ def test_tokenize
EOB
)))
)
end

########
def test_tokenize_4
assert_equals(
msg,
"tokenize 4",
strip_indent(
<<-EOB
plain (aa )
Expand All @@ -127,10 +128,11 @@ def test_tokenize
EOB
)))
)
end

########
def test_tokenize_5
assert_equals(
msg,
"tokenize 5",
strip_indent(
<<-EOB
plain (aa )
Expand All @@ -144,10 +146,11 @@ def test_tokenize
EOB
)))
)
end

########
def test_tokenize_6
assert_equals(
msg + "begin with multiline comment",
"tokenize - begin with multiline comment",
strip_indent(
<<-EOB
comment_multi (/* bb */)
Expand All @@ -163,12 +166,9 @@ def test_tokenize
end


def test_string_in_string
msg = "string_in_string"

########
def test_string_in_string_1
assert_equals(
msg,
"string_in_string 1",
strip_indent(
<<-EOB
quote_double ("aa'bb'cc")
Expand All @@ -180,10 +180,11 @@ def test_string_in_string
EOB
)))
)
end

########
def test_string_in_string_2
assert_equals(
msg,
"string_in_string 2",
strip_indent(
<<-EOB
quote_single ('aa"bb"cc')
Expand All @@ -198,12 +199,9 @@ def test_string_in_string
end


def test_comment_in_comment
msg = "comment_in_comment - "

########
def test_comment_in_comment_1
assert_equals(
msg,
"comment_in_comment 1",
strip_indent(
<<-EOB
comment_single (--a--b)
Expand All @@ -215,10 +213,11 @@ def test_comment_in_comment
EOB
)))
)
end

########
def test_comment_in_comment_2
assert_equals(
msg,
"comment_in_comment 2",
strip_indent(
<<-EOB
comment_single (-- aa /* bb */)
Expand All @@ -230,10 +229,11 @@ def test_comment_in_comment
EOB
)))
)
end

########
def test_comment_in_comment_3
assert_equals(
msg,
"comment_in_comment 3",
strip_indent(
<<-EOB
comment_multi (/* aa /* bb */)
Expand All @@ -245,10 +245,11 @@ def test_comment_in_comment
EOB
)))
)
end

########
def test_comment_in_comment_4
assert_equals(
msg,
"comment_in_comment 4",
strip_indent(
<<-EOB
comment_multi (/* aa -- bb */)
Expand All @@ -263,12 +264,9 @@ def test_comment_in_comment
end


def test_string_in_comment
msg = "string_in_comment - "

########
def test_string_in_comment_1
assert_equals(
msg,
"string_in_comment 1",
strip_indent(
<<-EOB
comment_single (-- aa "bb" cc)
Expand All @@ -280,10 +278,11 @@ def test_string_in_comment
EOB
)))
)
end

########
def test_string_in_comment_2
assert_equals(
msg,
"string_in_comment 2",
strip_indent(
<<-EOB
comment_single (-- aa 'bb' cc)
Expand All @@ -295,10 +294,11 @@ def test_string_in_comment
EOB
)))
)
end

########
def test_string_in_comment_3
assert_equals(
msg,
"string_in_comment 3",
strip_indent(
<<-EOB
comment_multi (/* aa "bb" cc */)
Expand All @@ -310,10 +310,11 @@ def test_string_in_comment
EOB
)))
)
end

########
def test_string_in_comment_4
assert_equals(
msg,
"string_in_comment 4",
strip_indent(
<<-EOB
comment_multi (/* aa 'bb' cc */)
Expand All @@ -328,12 +329,9 @@ def test_string_in_comment
end


def test_comment_in_string
msg = "comment_in_string - "

########
def test_comment_in_string_1
assert_equals(
msg + "comment_single in quote_single",
"comment_in_string - comment_single in quote_single",
strip_indent(
<<-EOB
quote_single ('aa--bb')
Expand All @@ -345,10 +343,11 @@ def test_comment_in_string
EOB
)))
)
end

########
def test_comment_in_string_2
assert_equals(
msg + "comment_single in quote_double",
"comment_in_string - comment_single in quote_double",
strip_indent(
<<-EOB
quote_double ("aa--bb")
Expand All @@ -360,10 +359,11 @@ def test_comment_in_string
EOB
)))
)
end

########
def test_comment_in_string_3
assert_equals(
msg + "comment_multi in quote_double",
"comment_in_string - comment_multi in quote_double",
strip_indent(
<<-EOB
quote_double ("aa /* bb */ cc")
Expand All @@ -375,10 +375,11 @@ def test_comment_in_string
EOB
)))
)
end

########
def test_comment_in_string_4
assert_equals(
msg + "comment_multi in quote_double",
"comment_in_string - comment_multi in quote_double",
strip_indent(
<<-EOB
quote_single ('aa /* bb */ cc')
Expand All @@ -393,12 +394,9 @@ def test_comment_in_string
end


def test_string_escape
msg = "string_escape"

########
def test_string_escape_1
assert_equals(
msg,
"string_escape 1",
strip_indent(
<<-EOB
quote_double ("_a_\\\\_b_\n_c_\\'_d_")
Expand All @@ -410,10 +408,11 @@ def test_string_escape
EOB
)))
)
end

########
def test_string_escape_2
assert_equals(
msg,
"string_escape 2",
strip_indent(
<<-EOB
quote_single ('_a_\\\\_b_\n_c_\\'_d_')
Expand All @@ -425,10 +424,11 @@ def test_string_escape
EOB
)))
)
end

########
def test_string_escape_3
assert_equals(
msg,
"string_escape 3",
strip_indent(
<<-EOB
quote_double ("_a_""_b_")
Expand All @@ -440,10 +440,11 @@ def test_string_escape
EOB
)))
)
end

########
def test_string_escape_4
assert_equals(
msg,
"string_escape 4",
strip_indent(
<<-EOB
quote_single ('_a_''_b_')
Expand Down
Loading

0 comments on commit d97bc81

Please sign in to comment.