Skip to content

Commit 9af2712

Browse files
committed
modify test for junoser-squash
1 parent 01fdfff commit 9af2712

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

lib/junoser/squash.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,16 @@ class DeleteTransformer < Parslet::Transform
4545
end
4646

4747
class Squash
48-
def initialize(io)
49-
@io = io
48+
def initialize(io_or_string)
49+
@input = io_or_string
5050
@lines = []
5151
@parser = Junoser::Parser.new
5252
@transformer = DeleteTransformer.new
5353
end
5454

5555
def transform
56-
while l = $<.gets
56+
config = Junoser::Input.new(@input).read.split("\n")
57+
config.each do |l|
5758
l.strip!
5859
case l
5960
when /^set /

test/test_junoser-squash.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
require 'junoser/squash'
1+
require 'pathname'
2+
3+
$: << File.expand_path('../', Pathname.new(__FILE__).realpath)
24
require 'helper'
35

6+
$: << File.expand_path('../../lib', Pathname.new(__FILE__).realpath)
7+
require 'junoser/squash'
8+
9+
410
class TestCommentLine < Test::Unit::TestCase
511
config_subcommand = <<-EOS
612
set interfaces em0 unit 0 family inet address 192.0.2.1/32
@@ -26,19 +32,17 @@ class TestCommentLine < Test::Unit::TestCase
2632
# config_squash
2733

2834
test 'check subcommand function' do
29-
assert_equal(<<-EOS,Junoser::Squash.new(config_subcommand).transform)
30-
set interfaces em0 unit 0 family inet address 192.0.2.1/32
35+
assert_equal('set interfaces em0 unit 0 family inet address 192.0.2.1/32
3136
set interfaces em100 unit 0 family inet
32-
set interfaces em100 unit 0 family inet address 192.0.2.1/32
33-
EOS
37+
set interfaces em100 unit 0 family inet address 192.0.2.1/32',Junoser::Squash.new(config_subcommand).transform)
38+
3439
end
3540

3641
test 'check delete function' do
37-
assert_equal(<<-EOS,Junoser::Squash.new(config_delete).transform)
38-
set interfaces em0 unit 0 family inet address 192.0.2.0/32
42+
assert_equal('set interfaces em0 unit 0 family inet address 192.0.2.0/32
3943
set interfaces em10
4044
set interfaces em10 unit 20
41-
set interfaces em100 unit 100 family inet address 192.0.2.0/32
42-
EOS
45+
set interfaces em100 unit 100 family inet address 192.0.2.0/32',Junoser::Squash.new(config_delete).transform)
46+
4347
end
4448
end

0 commit comments

Comments
 (0)