Added tests for std::inspect

parent 14112415
Pipeline #37832594 passed with stages
in 12 minutes and 30 seconds
......@@ -20,6 +20,7 @@ import test::std::test_float
import test::std::test_format
import test::std::test_fs
import test::std::test_hash_map
import test::std::test_inspect
import test::std::test_integer
import test::std::test_nil
import test::std::test_string
......
import std::float::(INFINITY, NAN, NEGATIVE_INFINITY)
import std::test
import std::test::assert
object OneAttribute {
def init {
let @number = 10
}
}
object TwoAttributes {
def init {
let @first = 'first'
let @second = 10
}
}
object NestedObject {
def init {
let @child = OneAttribute.new
}
}
test.group('std::object::Object.inspect') do (g) {
g.test('Inspecting an empty Object') {
assert.equal(Object.new.inspect, 'Object')
}
g.test('Inspecting an Object with one attribute') {
let obj = OneAttribute.new
assert.equal(obj.inspect, 'OneAttribute { @number = 10 }')
}
g.test('Inspecting an Object with multiple attributes') {
let obj = TwoAttributes.new
let possible = [
'TwoAttributes { @first = "first", @second = 10 }',
'TwoAttributes { @second = 10, @first = "first" }'
]
# The order of attributes is not guaranteed, so we can't perform an equality
# comparison as such a test would randomly fail.
assert.true(possible.contains?(obj.inspect))
}
g.test('Inspecting an Object containing another Object') {
let obj = NestedObject.new
assert.equal(
obj.inspect,
'NestedObject { @child = OneAttribute { @number = 10 } }'
)
}
}
test.group('std::float::Float.inspect') do (g) {
g.test('Inspecting a Float') {
assert.equal(1.0.inspect, '1.0')
assert.equal(1.123.inspect, '1.123')
}
g.test('Inspecting a NaN') {
assert.equal(NAN.inspect, 'NaN')
}
g.test('Inspecting Infinity') {
assert.equal(INFINITY.inspect, 'Infinity')
}
g.test('Inspecting negative Infinity') {
assert.equal(NEGATIVE_INFINITY.inspect, '-Infinity')
}
}
test.group('std::integer::Integer.inspect') do (g) {
g.test('Inspecting an Integer') {
assert.equal(10.inspect, '10')
assert.equal(-10.inspect, '-10')
}
}
test.group('std::nil::Nil.inspect') do (g) {
g.test('Inspecting Nil') {
assert.equal(Nil.inspect, 'Nil')
}
}
test.group('std::boolean::Boolean.inspect') do (g) {
g.test('Inspecting Boolean') {
assert.equal(Boolean.inspect, 'Boolean')
}
g.test('Inspecting boolean True') {
assert.equal(True.inspect, 'True')
}
g.test('Inspecting boolean False') {
assert.equal(False.inspect, 'False')
}
}
test.group('std::string::String.inspect') do (g) {
g.test('Inspecting an empty String') {
assert.equal(''.inspect, '""')
}
g.test('Inspecting a non-empty String') {
assert.equal('foo'.inspect, '"foo"')
}
}
test.group('std::array::Array.inspect') do (g) {
g.test('Inspecting an empty Array') {
assert.equal([].inspect, '[]')
}
g.test('Inspecting a non-empty Array') {
assert.equal([10, 20].inspect, '[10, 20]')
}
}
test.group('std::hash_map::HashMap.inspect') do (g) {
g.test('Inspecting an empty HashMap') {
assert.equal(%[].inspect, '%[]')
}
g.test('Inspecting a non-empty HashMap') {
assert.equal(%['key': 10].inspect, '%["key": 10]')
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment