diff options
author | Steve Kemp <steve@steve.org.uk> | 2015-04-16 16:36:44 +0100 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2015-04-16 16:36:44 +0100 |
commit | e39d621fb414cf9ee95dabbe7c837e96cee65ea5 (patch) | |
tree | 5e9501419a2e20cf9a63bd8de0dbc8561ec0ca1e | |
parent | 8c2cf44335c4a2b16877454fa48f995c03b7f324 (diff) |
Test our enum-like type works as expected.
Specifically that we can get the value back as a string, and
work with the ordinal too.
-rw-r--r-- | lib/custodian/testfactory.rb | 12 | ||||
-rwxr-xr-x | t/test-testresult.t | 52 |
2 files changed, 64 insertions, 0 deletions
diff --git a/lib/custodian/testfactory.rb b/lib/custodian/testfactory.rb index 29d1f99..0f5a30d 100644 --- a/lib/custodian/testfactory.rb +++ b/lib/custodian/testfactory.rb @@ -15,6 +15,18 @@ module Custodian TEST_PASSED = 2 TEST_FAILED = 4 TEST_SKIPPED = 8 + + + # + # Allow one of our symbols to be converted back + # + def self.to_str(status) + for sym in self.constants + if self.const_get(sym) == status + return sym.to_s + end + end + end end diff --git a/t/test-testresult.t b/t/test-testresult.t new file mode 100755 index 0000000..6e8be4b --- /dev/null +++ b/t/test-testresult.t @@ -0,0 +1,52 @@ +#!/usr/bin/ruby -Ilib/ -I../lib/ + + +require 'test/unit' + +require 'custodian/testfactory' + + +class TestTestResult < Test::Unit::TestCase + + # + # Create the test suite environment: NOP. + # + def setup + end + + # + # Destroy the test suite environment: NOP. + # + def teardown + end + + + # + # Test the passed-symbol + # + def test_test_passed + f = Custodian::TestResult::TEST_PASSED + assert_equal(Custodian::TestResult.to_str(f), 'TEST_PASSED') + assert_equal(f, 2) + end + + + # + # Test the failed-symbol + # + def test_test_failed + f = Custodian::TestResult::TEST_FAILED + assert_equal(Custodian::TestResult.to_str(f), 'TEST_FAILED') + assert_equal(f, 4) + end + + # + # Test the skipped symbol + # + def test_test_skipped + f = Custodian::TestResult::TEST_SKIPPED + assert_equal(Custodian::TestResult.to_str(f), 'TEST_SKIPPED') + assert_equal(f, 8) + end + +end |