File: ComparatorTestCase.rb

package info (click to toggle)
quickfix 1.15.1%2Bdfsg-4
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye
  • size: 42,080 kB
  • sloc: cpp: 631,686; python: 129,549; ruby: 106,716; xml: 43,737; ansic: 7,668; java: 1,826; cs: 816; makefile: 544; sh: 462; sql: 313
file content (37 lines) | stat: -rw-r--r-- 1,503 bytes parent folder | download | duplicates (2)
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
require './Comparator'
require 'runit/testcase'

class ComparatorTestCase < RUNIT::TestCase

  def test_parsePatterns
    patterns = "10=\\d{1,3}\n52=\\d{8}-\\d2:\\d2:\\d2\n"
    comp = Comparator.new(patterns)
    assert_equals(/\d{1,3}/, comp[10])
    assert_equals(/\d{8}-\d2:\d2:\d2/, comp[52])
  end

  def test_compare
    patterns = "10=\\d{1,3}\n52=\\d{8}-\\d{2}:\\d{2}:\\d{2}\n"
    comp = Comparator.new(patterns)
    # matching fields
    assert(comp.compare("1=hello\0012=goodbye\001", "1=hello\0012=goodbye\001"))
    assert(comp.reason == nil)
    # non-matching field
    assert(!comp.compare("1=helloo\0012=goodbye\001", "1=hello\0012=goodbye\001"))
    assert(comp.reason == "Value in field (1) should be (helloo) but was (hello)")
    # out of order fields
    assert(!comp.compare("2=hello\0011=goodbye\001", "1=hello\0012=goodbye\001"))
    assert(comp.reason == "Expected field (2) but found field (1)")
    # different number of fields
    assert(!comp.compare("1=hello\001", "1=hello\0012=goodbye\001"))
    assert(comp.reason == "Number of fields do not match")
    # mathing non-deterministic field
    assert(comp.compare(
	"1=hello\0012=goodbye\00152=12345678-12:23:34\001", "1=hello\0012=goodbye\00152=87654321-98:87:76\001"))
    # non-matching non-deterministic field
    assert(!comp.compare(
	"1=hello\0012=goodbye\00152=12345678-12:23:34\001", "1=hello\0012=goodbye\00152=7654321-98:87:76\001"))
    assert(comp.reason == "Field (52) does not match pattern")
  end

end