Revert "tests: add more tests on interfaces "

This reverts commit 538662d99a.
pull/4847/head
Alexander Medvednikov 2020-05-11 15:19:55 +02:00
parent aacc35db19
commit 2618b4fbd3
1 changed files with 9 additions and 23 deletions

View File

@ -30,9 +30,9 @@ fn (c mut Cat) set_breed(new string) {
c.breed = new
}
// utility function to override default convert to string, as a sample
// utility function to convert to string, as a sample
fn (c Cat) str() string {
return 'Custom string conversion for Cat: $c.breed'
return 'Cat: $c.breed'
}
fn (d Dog) speak(s string) {
@ -53,8 +53,7 @@ fn (d mut Dog) set_breed(new string) {
println('Nah')
}
// do not add to Dog the utility function 'str', so the default one will be used, as a sample
// do not add to Dog the utility function 'str', as a sample
fn test_todo() {
if true {
} else {
@ -66,9 +65,10 @@ fn perform_speak(a Animal) {
assert true
name := a.name()
assert name == 'Dog' || name == 'Cat'
// if a is Dog {
// assert name == 'Dog'
// }
println(a.name())
println('Got animal of type: ${typeof(a)}') // TODO: get implementation type (if possible)
// assert a is Dog || a is Cat // TODO: enable when available
}
fn perform_speak_on_ptr(a &Animal) {
@ -130,36 +130,22 @@ fn test_perform_name_detailed() {
dog := Dog{
breed: 'Labrador Retriever'
}
println('Test on Dog: "$dog" ...') // using default conversion to string
println('Test on Dog: $dog ...')
perform_name_detailed(dog)
cat := Cat{}
println('Test on empty Cat: "$cat" ...')
println('Test on Cat: $cat ...')
perform_speak(cat)
println('Test on a Persian Cat: ...')
println('Test on another Cat: ...')
perform_speak(Cat{
breed: 'Persian'
})
cat_persian2 := Cat{
breed: 'Persian'
}
println('Test on another Persian Cat: "$cat_persian2" ...')
perform_speak(cat_persian2)
cat_persian2_str := cat_persian2.str()
println("Persian Cat 2: '$cat_persian2_str' ...")
assert cat_persian2_str == "Custom string conversion for Cat: Persian"
println('Test (dummy/empty) on array of animals ...')
handle_animals([dog, cat])
handle_animals_mutable([dog, cat])
assert true
}
fn handle_animals(a []Animal) {
}
fn handle_animals_mutable(mut a []Animal) {
}
interface Register {
register()
}