-
-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathformat_spec.cr
114 lines (96 loc) · 5.23 KB
/
format_spec.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
require "./spec_helper"
context "format" do
before_all do
FileUtils.rm_rf "source.mint"
end
after_all do
FileUtils.rm_rf "source.mint"
end
formatted_code =
<<-MINT
type Test {
file : String
}
MINT
unformatted_code =
<<-MINT
typeTest{file:String}
MINT
it "displays help with '--help' flag" do
expect_output ["format", "--help"], <<-TEXT
Usage:
×××× format [flags...] <pattern> [arg...]
Formats "*.mint" files.
Flags:
--check # Checks that formatting code produces no changes.
--help # Displays help for the current command.
--stdin # Formats code from STDIN and writes it to STDOUT.
Arguments:
pattern # The pattern which determines which files to format.
TEXT
end
it "formats code from STDIN" do
expect_output ["format", "--stdin"], <<-TEXT, unformatted_code
type Test {
file : String
}
TEXT
end
it "check code from STDIN (not formatted)" do
expect_output ["format", "--stdin", "--check"], <<-TEXT, unformatted_code
Mint - Checking source from STDIN
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Source is not formatted!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
There was an error, exiting...
TEXT
end
it "check code from STDIN (formatted)" do
expect_output ["format", "--stdin", "--check"], <<-TEXT, formatted_code + "\n"
Mint - Checking source from STDIN
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Source is formatted!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
All done in ××××!
TEXT
end
it "nothing to format" do
expect_output ["format"], <<-TEXT
Mint - Formatting files
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Nothing to format!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
All done in ××××!
TEXT
end
it "some files formatted" do
File.write("source.mint", unformatted_code)
expect_output ["format", "source.mint"], <<-TEXT
Mint - Formatting files
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Formatted: source.mint
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
All done in ××××!
TEXT
end
it "some files not formatted (--check)" do
File.write("source.mint", unformatted_code)
expect_output ["format", "source.mint", "--check"], <<-TEXT
Mint - Formatting files
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Not formatted: source.mint
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
All done in ××××!
TEXT
end
it "all files formatted" do
File.write("source.mint", formatted_code + "\n")
expect_output ["format", "source.mint"], <<-TEXT
Mint - Formatting files
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
All files are formatted!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
All done in ××××!
TEXT
end
end