class TestCase

class TestCase

lib/unittest/test_case.tya:2

TestCase provides assertion helpers for unittest suites.

Source
# TestCase provides assertion helpers for unittest suites.
class TestCase
  # TestCase.assert provides the unittest/TestCase standard library operation.
  # @param cond Any cond value.
  # @param desc Any desc value.
  # @return Any the resulting value.
  assert: cond, desc ->
    if not cond
      raise error({ kind: "unittest_fail", message: desc })

  # assert_equal fails the current test when expected and actual differ.
  # @param expected Any expected value.
  # @param actual Any actual value.
  # @param desc Any desc value.
  # @return Any the resulting value.
  assert_equal: expected, actual, desc ->
    if not equal(expected, actual)
      msg = "{desc}: expected {expected}, got {actual}"
      raise error({ kind: "unittest_fail", message: msg })

  # TestCase.assert_falsy provides the unittest/TestCase standard library operation.
  # @param cond Any cond value.
  # @param desc Any desc value.
  # @return Any the resulting value.
  assert_falsy: cond, desc ->
    if cond
      raise error({ kind: "unittest_fail", message: desc })

  # TestCase.assert_nil provides the unittest/TestCase standard library operation.
  # @param value String value value.
  # @param desc Any desc value.
  # @return Any the resulting value.
  assert_nil: value, desc ->
    if value != nil
      raise error({ kind: "unittest_fail", message: "{desc}: expected nil, got {value}" })

  # TestCase.assert_not_equal provides the unittest/TestCase standard library operation.
  # @param left Any left value.
  # @param right Any right value.
  # @param desc Any desc value.
  # @return Any the resulting value.
  assert_not_equal: left, right, desc ->
    if equal(left, right)
      raise error({ kind: "unittest_fail", message: "{desc}: expected not equal" })

  # assert_raises fails unless body raises an error.
  # @param body String body value.
  # @return Any the resulting value.
  assert_raises: body ->
    raised = false
    try
      body()
    catch _
      raised = true
    if not raised
      raise error({ kind: "unittest_fail", message: "expected raise but none" })

  # TestCase.fail provides the unittest/TestCase standard library operation.
  # @param msg Any msg value.
  # @return Any the resulting value.
  fail: msg ->
    raise error({ kind: "unittest_fail", message: msg })

Methods

assert

TestCase.assert(cond, desc)

lib/unittest/test_case.tya:7

TestCase.assert provides the unittest/TestCase standard library operation.

Source
  # TestCase.assert provides the unittest/TestCase standard library operation.
  # @param cond Any cond value.
  # @param desc Any desc value.
  # @return Any the resulting value.
  assert: cond, desc ->
    if not cond
      raise error({ kind: "unittest_fail", message: desc })

assert_equal

TestCase.assert_equal(expected, actual, desc)

lib/unittest/test_case.tya:16

assert_equal fails the current test when expected and actual differ.

Source
  # assert_equal fails the current test when expected and actual differ.
  # @param expected Any expected value.
  # @param actual Any actual value.
  # @param desc Any desc value.
  # @return Any the resulting value.
  assert_equal: expected, actual, desc ->
    if not equal(expected, actual)
      msg = "{desc}: expected {expected}, got {actual}"
      raise error({ kind: "unittest_fail", message: msg })

assert_falsy

TestCase.assert_falsy(cond, desc)

lib/unittest/test_case.tya:25

TestCase.assert_falsy provides the unittest/TestCase standard library operation.

Source
  # TestCase.assert_falsy provides the unittest/TestCase standard library operation.
  # @param cond Any cond value.
  # @param desc Any desc value.
  # @return Any the resulting value.
  assert_falsy: cond, desc ->
    if cond
      raise error({ kind: "unittest_fail", message: desc })

assert_nil

TestCase.assert_nil(value, desc)

lib/unittest/test_case.tya:33

TestCase.assert_nil provides the unittest/TestCase standard library operation.

Source
  # TestCase.assert_nil provides the unittest/TestCase standard library operation.
  # @param value String value value.
  # @param desc Any desc value.
  # @return Any the resulting value.
  assert_nil: value, desc ->
    if value != nil
      raise error({ kind: "unittest_fail", message: "{desc}: expected nil, got {value}" })

assert_not_equal

TestCase.assert_not_equal(left, right, desc)

lib/unittest/test_case.tya:42

TestCase.assert_not_equal provides the unittest/TestCase standard library operation.

Source
  # TestCase.assert_not_equal provides the unittest/TestCase standard library operation.
  # @param left Any left value.
  # @param right Any right value.
  # @param desc Any desc value.
  # @return Any the resulting value.
  assert_not_equal: left, right, desc ->
    if equal(left, right)
      raise error({ kind: "unittest_fail", message: "{desc}: expected not equal" })

assert_raises

TestCase.assert_raises(body)

lib/unittest/test_case.tya:49

assert_raises fails unless body raises an error.

Source
  # assert_raises fails unless body raises an error.
  # @param body String body value.
  # @return Any the resulting value.
  assert_raises: body ->
    raised = false
    try
      body()
    catch _
      raised = true
    if not raised
      raise error({ kind: "unittest_fail", message: "expected raise but none" })

fail

TestCase.fail(msg)

lib/unittest/test_case.tya:61

TestCase.fail provides the unittest/TestCase standard library operation.

Source
  # TestCase.fail provides the unittest/TestCase standard library operation.
  # @param msg Any msg value.
  # @return Any the resulting value.
  fail: msg ->
    raise error({ kind: "unittest_fail", message: msg })