packages feed

zeolite-lang-0.4.0.0: tests/function-merging.0rt

/* -----------------------------------------------------------------------------
Copyright 2020 Kevin P. Barry

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
----------------------------------------------------------------------------- */

// Author: Kevin P. Barry [ta0kira@gmail.com]

testcase "internal merge" {
  success Test$run()
}

@value interface Interface {
  call () -> (Interface)
}

concrete Value {
  refines Interface
  @type create () -> (Value)
}

define Value {
  create () {
    return Value{}
  }

  @value call () -> (Value)
  call () {
    return self
  }
}

define Test {
  run () {
    \ Value$create().call().call()
  }
}

concrete Test {
  @type run () -> ()
}


testcase "internal merge failed" {
  error
  require "Interface2"
}

@value interface Interface {}

@value interface Interface2 {
  refines Interface
  call () -> (Interface2)
}

concrete Value {
  refines Interface2
  @type create () -> (Value)
}

define Value {
  create () {
    return Value{}
  }

  @value call () -> (Interface)
  call () {
    return self
  }
}

define Test {
  run () {}
}

concrete Test {
  @type run () -> ()
}


testcase "external merge" {
  success Test$run()
}

@value interface Interface {
  call () -> (Interface)
}

concrete Value {
  refines Interface
  @type create () -> (Value)
  @value call () -> (Value)
}

define Value {
  create () {
    return Value{}
  }

  call () {
    return self
  }
}

define Test {
  run () {
    \ Value$create().call().call()
  }
}

concrete Test {
  @type run () -> ()
}


testcase "external merge failed" {
  error
  require "Interface2"
}

@value interface Interface {}

@value interface Interface2 {
  refines Interface
  call () -> (Interface2)
}

concrete Value {
  refines Interface2
  @type create () -> (Value)
  @value call () -> (Interface)
}

define Value {
  create () {
    return Value{}
  }

  call () {
    return self
  }
}

define Test {
  run () {}
}

concrete Test {
  @type run () -> ()
}