Exit Full View

Feather2 / feather2-foocad / src / test / kotlin / uk.co.nickthecoder / feather / foocad / RealProblemsInScripts.kt

package uk.co.nickthecoder.feather.foocad

import junit.framework.TestCase.assertEquals
import org.junit.Test

class RealProblemsInScripts {

    @Test
    fun applyLength() {
        val script = """
            class DrawerSlide {
                var length = 10
            }
            class ComponentDrawer() {
                fun slide() = DrawerSlide().apply {
                    // The length field wasn't found. A bug with `apply`.
                    length = 20
                }
            }
            """
        assertEquals(1, extensionsConfig.compile(script).allClassNames.size)
    }

    @Test
    fun pairSecond() {
        val script = """
            class WithVector2 : AbstractModel() {
                fun test() : double {
                   val circle = Circle(10)
                   val path = circle.firstPath
                   // The result of `Pair.getSecond()` wasn't being cast to a Vector2, therefore .getX() failed. 
                   return path.extent.second.x
               }
            }
            """
        assertEquals(10.0, extensionsConfig.runTest(script))

    }

}