Skip to content

Commit

Permalink
Merge pull request #1127 from BallAerospace/extract_error
Browse files Browse the repository at this point in the history
Extract items using rindex
  • Loading branch information
ryanmelt authored Mar 9, 2020
2 parents 48f5543 + 052889c commit 6570779
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/cosmos/script/extract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def extract_fields_from_check_text(text)
return [target_name, packet_name, item_name, comparison_to_eval] if split_string.length == 3
raise "ERROR: Check improperly specified: #{text}" if split_string.length < 4
split_string = text.split(/ /) # Split on regex spaces to preserve spaces in comparison
index = split_string.index(item_name)
index = split_string.rindex(item_name)
comparison_to_eval = split_string[(index + 1)..(split_string.length - 1)].join(" ")
raise "ERROR: Use '==' instead of '=': #{text}" if split_string[3] == '='
return [target_name, packet_name, item_name, comparison_to_eval]
Expand Down
5 changes: 4 additions & 1 deletion spec/script/extract_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ module Cosmos
expect(extract_fields_from_check_text("TARGET PACKET ITEM < 5")).to eql(['TARGET', 'PACKET', 'ITEM', '< 5'])
end

it "should support target packet items named the same" do
expect(extract_fields_from_check_text("TEST TEST TEST == 5")).to eql(['TEST', 'TEST', 'TEST', '== 5'])
end

it "should complain about trying to do an = comparison" do
expect { extract_fields_from_check_text("TARGET PACKET ITEM = 5") }.to raise_error(/ERROR: Use/)
end
Expand All @@ -160,4 +164,3 @@ module Cosmos

end
end

0 comments on commit 6570779

Please sign in to comment.