Skip to content

Commit

Permalink
Apply formatter changes from previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
RX14 authored and asterite committed Jun 6, 2017
1 parent f833a82 commit abd2dfd
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 115 deletions.
8 changes: 4 additions & 4 deletions spec/compiler/semantic/module_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,23 @@ describe "Semantic: module" do
class Foo::Bar
end
Foo
") {
") do
foo = types["Foo"]
foo.module?.should be_true
foo.metaclass
}
end
end

it "declares module automatically if not previously declared when declaring a module" do
assert_type("
module Foo::Bar
end
Foo
") {
") do
foo = types["Foo"]
foo.module?.should be_true
foo.metaclass
}
end
end

it "includes generic module with another generic type" do
Expand Down
160 changes: 83 additions & 77 deletions spec/std/pretty_print_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -226,22 +226,22 @@ describe PrettyPrint do
END

it "tail group" do
text = String.build { |io|
PrettyPrint.format(io, 10) { |q|
q.group {
q.group {
text = String.build do |io|
PrettyPrint.format(io, 10) do |q|
q.group do
q.group do
q.text "abc"
q.breakable
q.text "def"
}
q.group {
end
q.group do
q.text "ghi"
q.breakable
q.text "jkl"
}
}
}
}
end
end
end
end
text.should eq("abc defghi\njkl")
end
end
Expand All @@ -258,51 +258,51 @@ private class Tree
end

def show(q)
q.group {
q.group do
q.text @string
q.nest(@string.size) {
q.nest(@string.size) do
unless @children.empty?
q.text '['
q.nest(1) {
q.nest(1) do
first = true
@children.each { |t|
@children.each do |t|
if first
first = false
else
q.text ','
q.breakable
end
t.show(q)
}
}
end
end
q.text ']'
end
}
}
end
end
end

def altshow(q)
q.group {
q.group do
q.text @string
unless @children.empty?
q.text '['
q.nest(2) {
q.nest(2) do
q.breakable
first = true
@children.each { |t|
@children.each do |t|
if first
first = false
else
q.text ','
q.breakable
end
t.altshow(q)
}
}
end
end
q.breakable
q.text ']'
end
}
end
end
end

Expand All @@ -319,79 +319,85 @@ private def tree
end

private def tree(width)
String.build { |io|
String.build do |io|
PrettyPrint.format(io, width) { |q| tree.show(q) }
}
end
end

private def tree_alt(width)
String.build { |io|
String.build do |io|
PrettyPrint.format(io, width) { |q| tree.altshow(q) }
}
end
end

private def hello(width)
String.build { |io|
PrettyPrint.format(io, width) { |hello|
hello.group {
hello.group {
hello.group {
hello.group {
String.build do |io|
PrettyPrint.format(io, width) do |hello|
hello.group do
hello.group do
hello.group do
hello.group do
hello.text "hello"
hello.breakable; hello.text "a"
}
end
hello.breakable; hello.text "b"
}
end
hello.breakable; hello.text "c"
}
end
hello.breakable; hello.text "d"
}
}
}
end
end
end
end

private def stritc_pretty(width)
String.build do |io|
PrettyPrint.format(io, width) { |q|
q.group {
q.group { q.nest(2) {
q.text "if"; q.breakable
q.group {
q.nest(2) {
q.group { q.text "a"; q.breakable; q.text "==" }
q.breakable; q.text "b"
}
}
} }
PrettyPrint.format(io, width) do |q|
q.group do
q.group do
q.nest(2) do
q.text "if"; q.breakable
q.group do
q.nest(2) do
q.group { q.text "a"; q.breakable; q.text "==" }
q.breakable; q.text "b"
end
end
end
end
q.breakable
q.group { q.nest(2) {
q.text "then"; q.breakable
q.group {
q.nest(2) {
q.group { q.text "a"; q.breakable; q.text "<<" }
q.breakable; q.text "2"
}
}
} }
q.group do
q.nest(2) do
q.text "then"; q.breakable
q.group do
q.nest(2) do
q.group { q.text "a"; q.breakable; q.text "<<" }
q.breakable; q.text "2"
end
end
end
end
q.breakable
q.group { q.nest(2) {
q.text "else"; q.breakable
q.group {
q.nest(2) {
q.group { q.text "a"; q.breakable; q.text "+" }
q.breakable; q.text "b"
}
}
} }
}
}
q.group do
q.nest(2) do
q.text "else"; q.breakable
q.group do
q.nest(2) do
q.group { q.text "a"; q.breakable; q.text "+" }
q.breakable; q.text "b"
end
end
end
end
end
end
end
end

private def fill(width)
String.build { |io|
PrettyPrint.format(io, width) { |q|
q.group {
String.build do |io|
PrettyPrint.format(io, width) do |q|
q.group do
q.text "abc"
q.fill_breakable
q.text "def"
Expand All @@ -405,9 +411,9 @@ private def fill(width)
q.text "pqr"
q.fill_breakable
q.text "stu"
}
}
}
end
end
end
end

private def assert_hello(range, expected)
Expand Down
16 changes: 8 additions & 8 deletions spec/std/string_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -984,10 +984,10 @@ describe "String" do
end

it "subs char with string" do
replaced = "foobar".sub { |char|
replaced = "foobar".sub do |char|
char.should eq 'f'
"some"
}
end
replaced.bytesize.should eq(9)
replaced.should eq("someoobar")

Expand All @@ -996,16 +996,16 @@ describe "String" do
end

it "subs with regex and block" do
actual = "foo booor booooz".sub(/o+/) { |str|
actual = "foo booor booooz".sub(/o+/) do |str|
"#{str}#{str.size}"
}
end
actual.should eq("foo2 booor booooz")
end

it "subs with regex and block with group" do
actual = "foo booor booooz".sub(/(o+).*?(o+)/) { |str, match|
actual = "foo booor booooz".sub(/(o+).*?(o+)/) do |str, match|
"#{match[1].size}#{match[2].size}"
}
end
actual.should eq("f23r booooz")
end

Expand Down Expand Up @@ -1053,10 +1053,10 @@ describe "String" do
end

it "subs with string and block" do
result = "foo boo".sub("oo") { |value|
result = "foo boo".sub("oo") do |value|
value.should eq("oo")
"a"
}
end
result.should eq("fa boo")
end

Expand Down
16 changes: 10 additions & 6 deletions src/benchmark.cr
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ require "./benchmark/**"
#
# n = 5000000
# Benchmark.bm do |x|
# x.report("times:") { n.times do
# a = "1"
# end }
# x.report("upto:") { 1.upto(n) do
# a = "1"
# end }
# x.report("times:") do
# n.times do
# a = "1"
# end
# end
# x.report("upto:") do
# 1.upto(n) do
# a = "1"
# end
# end
# end
# ```
#
Expand Down
Loading

0 comments on commit abd2dfd

Please sign in to comment.