Skip to content

Commit

Permalink
Add some specs related to ECR files
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodywasishere committed Jan 12, 2025
1 parent b60a03f commit c0967fd
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 0 deletions.
7 changes: 7 additions & 0 deletions spec/ameba/rule/layout/trailing_blank_lines_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,12 @@ module Ameba::Rule::Layout
issue.message.should eq "Trailing newline missing"
end
end

{% if compare_versions(Crystal::VERSION, "1.15.0") >= 0 %}
it "fails if there more then one blank line at the end of an ECR source" do
source = expect_issue subject, "a = 1\n \n # error: Excessive trailing newline detected", "source.ecr"
expect_no_corrections source
end
{% end %}
end
end
11 changes: 11 additions & 0 deletions spec/ameba/rule/layout/trailing_whitespace_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,16 @@ module Ameba::Rule::Layout

expect_correction source, "whitespace at the end"
end

{% if compare_versions(Crystal::VERSION, "1.15.0") >= 0 %}
it "fails if there is a line with trailing whitespace in an ECR file" do
source = expect_issue subject,
"whitespace at the end \n" \
" # ^^ error: Trailing whitespace detected",
path: "source.ecr"

expect_correction source, "whitespace at the end"
end
{% end %}
end
end
13 changes: 13 additions & 0 deletions spec/ameba/rule/lint/formatting_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,18 @@ module Ameba::Rule::Lint
end
end
end

{% if compare_versions(Crystal::VERSION, "1.15.0") >= 0 %}
it "passes ECR files regardless of formatting" do
source = expect_no_issues subject, <<-CRYSTAL, "source.ecr"
<%
def method(a,b,c=0)
a+b+c
end
%>
CRYSTAL
end
{% end %}
end
end
12 changes: 12 additions & 0 deletions spec/ameba/rule/lint/literal_in_condition_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,17 @@ module Ameba::Rule::Lint
issue.end_location.to_s.should eq "source.cr:1:20"
issue.message.should eq "Literal value found in conditional"
end

{% if compare_versions(Crystal::VERSION, "1.15.0") >= 0 %}
it "fails if there is a predicate in if conditional in an ECR file" do
s = Source.new %(
<% if "string" %>
:ok
<% end %>
), "source.ecr"

subject.catch(s).should_not be_valid
end
{% end %}
end
end
15 changes: 15 additions & 0 deletions spec/ameba/rule/lint/unused_literal_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -295,5 +295,20 @@ module Ameba::Rule::Lint
CRYSTAL
end
{% end %}

{% if compare_versions(Crystal::VERSION, "1.15.0") >= 0 %}
it "passes if a string is used in an assign directive in an ECR file" do
expect_no_issues subject, <<-CRYSTAL, path: "source.ecr"
<%= "hello world" %>
CRYSTAL
end

it "fails if a string is unused in an ECR file" do
expect_issue subject, <<-CRYSTAL, path: "source.ecr"
<% "hello world" %>
# ^^^^^^^^^^^^^ error: Literal value is not used
CRYSTAL
end
{% end %}
end
end
26 changes: 26 additions & 0 deletions spec/ameba/source_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,31 @@ module Ameba
CRYSTAL
end
end

{% if compare_versions(Crystal::VERSION, "1.15.0") >= 0 %}
describe "#ast" do
it "parses an ECR file" do
source = Source.new <<-ECR, "filename.ecr"
hello <%= "world" %>
ECR

source.ast.to_s.should eq(<<-CRYSTAL)
__str__ << "hello "
("world").to_s(__str__)
CRYSTAL
end

it "raises an exception when ECR parsing fails" do
source = Source.new <<-ECR, "filename.ecr"
hello <%= "world" >
ECR

expect_raises(Crystal::SyntaxException) do
source.ast
end
end
end
{% end %}
end
end

0 comments on commit c0967fd

Please sign in to comment.