开发者

RSpec test of Treetop parser output doesn't match when it should

开发者 https://www.devze.com 2023-01-10 17:20 出处:网络
I have this spec: it \'can parse armies with only section headers\' do list = <<-LIST :Core :Special

I have this spec:

it 'can parse armies with only section headers' do
  list = <<-LIST
  :Core
  :Special
  :Omgg
  :Moarheaders
  LIST
  expected_output = "## Core\n## Special\n## Omgg\n## Moarheaders\n"
  parsed = @parser.parse(list)
  parsed.should_not be_nil
  parsed.transform.should be expected_output
end

Which produces this output:

expected ## Core
## Special
## Omgg
## Moarheaders
, got "## Core\n## Special\n## Omgg\n## Moarheaders\n"

If I remove the double quotes, I get this output:

expected ## Core\n## Special\n## Omgg\n## Moarheaders\n, 
got     "## Core\n## Special\n## Omgg\n## Moarheaders\n"

If I add quotes to my expected_output开发者_如何学C, I get this: (expected_output = '"## Core\n## Special\n## Omgg\n## Moarheaders\n"')

expected "## Core\n## Special\n## Omgg\n## Moarheaders\n", 
got      "## Core\n## Special\n## Omgg\n## Moarheaders\n"

What's going on here?

I can't get the Treetop result to evaluate the \n as newlines, and I can't get the expected_output to match regardless of what I try.

I'm confused.


Did you try:

parsed.transform.should == expected_output

be might use object identity instead of comparing the string values.

0

精彩评论

暂无评论...
验证码 换一张
取 消