Fix formatting in some of test data files.

Adapted from https://github.com/develar/kotlin/commit/a9e0a42fb1347fa8e21c86b5a073ef8a7c873da0.
This commit is contained in:
Pavel V. Talanov
2012-08-10 14:06:23 +04:00
parent 12d9b25189
commit 7a22ad099a
31 changed files with 227 additions and 234 deletions
@@ -1,7 +1,6 @@
package foo package foo
class A() { class A() {
var i = 0 var i = 0
fun f() { fun f() {
@@ -21,4 +20,4 @@ fun box() : Boolean {
val a = A() val a = A()
a.f() a.f()
return a.i == 3 return a.i == 3
} }
@@ -24,4 +24,4 @@ fun box() : Boolean {
sum += f() sum += f()
} }
return (sum == 27) return (sum == 27)
} }
@@ -1,7 +1,7 @@
fun box() : String { fun box(): String {
return if (apply( 5, {(arg: Int) -> arg + 13 } ) == 18) "OK" else "fail" return if (apply(5) {(arg: Int) -> arg + 13 } == 18) "OK" else "fail"
} }
fun apply(arg : Int, f : (p:Int) -> Int) : Int { fun apply(arg: Int, f: (p: Int) -> Int): Int {
return f(arg) return f(arg)
} }
@@ -1,8 +1,8 @@
fun box() : String { fun box(): String {
val cl = 39 val cl = 39
return if (sum(200, { val ff = {cl}; ff() }) == 239) "OK" else "FAIL" return if (sum(200, {val ff = {cl}; ff()}) == 239) "OK" else "FAIL"
} }
fun sum(arg:Int, f : () -> Int) : Int { fun sum(arg: Int, f: ()->Int): Int {
return arg + f() return arg + f()
} }
@@ -1,13 +1,13 @@
class Point(val x : Int, val y : Int) class Point(val x: Int, val y: Int)
fun box() : String { fun box(): String {
val answer = apply(Point(3, 5), { Point.(scalar : Int) : Point -> val answer = apply(Point(3, 5), { Point.(scalar: Int) : Point ->
Point(x * scalar, y * scalar) Point(x * scalar, y * scalar)
}) })
return if (answer.x == 6 && answer.y == 10) "OK" else "FAIL" return if (answer.x == 6 && answer.y == 10) "OK" else "FAIL"
} }
fun apply(arg:Point, f : Point.(scalar : Int) -> Point) : Point { fun apply(arg: Point, f: Point.(scalar: Int) -> Point): Point {
return arg.f(2) return arg.f(2)
} }
@@ -2,12 +2,12 @@ import java.util.*
class Lifetime() { class Lifetime() {
val attached = ArrayList< Function0<Unit> >() val attached = ArrayList< Function0<Unit> >()
public fun attach(action : ()->Unit) public fun attach(action : ()->Unit)
{ {
attached.add(action) attached.add(action)
} }
fun close() fun close()
{ {
for(x in attached) x() for(x in attached) x()
@@ -18,51 +18,52 @@ class Lifetime() {
public class Viewable<T>() public class Viewable<T>()
{ {
val items = ArrayList<T>() val items = ArrayList<T>()
fun add(item:T) fun add(item:T)
{ {
items.add(item) items.add(item)
} }
fun remove(item:T) fun remove(item:T)
{ {
items.remove(item) items.remove(item)
} }
fun view(lifetime: Lifetime, viewer: (itemLifetime:Lifetime, item:T) -> Unit) fun view(lifetime: Lifetime, viewer: (itemLifetime: Lifetime, item: T) -> Unit) {
{ for (item in items) {
for(item in items) viewer(lifetime, item)
viewer(lifetime, item) }
} }
} }
fun lifetime(body: (Lifetime)->Unit) fun lifetime(body: (Lifetime)->Unit) {
{ val l = Lifetime()
val l = Lifetime() body(l)
body(l) l.close()
l.close()
} }
fun<T> Dump(items:ArrayList<T>) fun<T> Dump(items: ArrayList<T>) {
{ for(item in items) {
for(item in items) print(item.toString() + ", ")
print(item.toString() + ", ") }
println("end") println("end")
} }
fun main(args:Array<String>) fun main(args: Array<String>) {
{ val v = Viewable<Int>()
val v = Viewable<Int>() val x = ArrayList<Int>()
val x = ArrayList<Int>() v.add(1)
v.add(1) v.add(2)
v.add(2) v.add(3)
v.add(3) lifetime() {
lifetime( v.view(it) {itemLifetime, item ->
{ x.add(item)
v.view(it, {(itemLifetime, item)-> Dump(x)
x.add(item) itemLifetime.attach() {
Dump(x) x.remove(item as Any);
itemLifetime.attach { x.remove(item as Any); Dump(x); println("!") } Dump(x);
}) println("!")
}) }
}
}
} }
@@ -1,9 +1,9 @@
package foo package foo
fun box() : Boolean { fun box(): Boolean {
var sum = 0 var sum = 0
val adder = {(a: Int) -> sum += a } val adder = {(a: Int) -> sum += a}
adder(3) adder(3)
adder(2) adder(2)
return sum == 5 return sum == 5
} }
@@ -1,6 +1,5 @@
package foo package foo
fun f(a : Int = 2, b : Int = 3) = a + b fun f(a : Int = 2, b : Int = 3) = a + b
fun box() : Boolean fun box() : Boolean
@@ -1,14 +1,14 @@
package foo package foo
fun f(a: (Int) -> Int) = a(1) fun f(a: (Int) -> Int) = a(1)
fun box() : Boolean { fun box(): Boolean {
if (f() { if (f() {
it + 2 it + 2
} != 3) return false } != 3) return false
if (f() {(a : Int) -> a * 300} != 300) return false; if (f() {(a: Int) -> a * 300} != 300) return false;
return true return true
} }
@@ -2,16 +2,16 @@ package foo
var b = 0 var b = 0
fun loop(var times : Int) { fun loop(var times: Int) {
while(times > 0) { while (times > 0) {
val u = {(value : Int) -> val u = {(value: Int) ->
b = b + 1 b = b + 1
} }
u(times--) u(times--)
} }
} }
fun box() : Boolean { fun box(): Boolean {
loop(5) loop(5)
return b == 5 return b == 5
} }
@@ -1,7 +1,7 @@
package foo package foo
class Data(val rawData : Array<Int>, val width : Int, val height : Int) { class Data(val rawData: Array<Int>, val width: Int, val height: Int) {
fun get(x : Int, y : Int) : ColorLike { fun get(x: Int, y: Int): ColorLike {
return object : ColorLike { return object : ColorLike {
override val red: Int = rawData[(y * width + x) * 4 + 0]; override val red: Int = rawData[(y * width + x) * 4 + 0];
override val green: Int = rawData[(y * width + x) * 4 + 1]; override val green: Int = rawData[(y * width + x) * 4 + 1];
@@ -9,13 +9,13 @@ class Data(val rawData : Array<Int>, val width : Int, val height : Int) {
} }
} }
fun set(x : Int, y : Int, color : ColorLike) { fun set(x: Int, y: Int, color: ColorLike) {
rawData[(y * width + x) * 4 + 0] = color.red; rawData[(y * width + x) * 4 + 0] = color.red;
rawData[(y * width + x) * 4 + 1] = color.green; rawData[(y * width + x) * 4 + 1] = color.green;
rawData[(y * width + x) * 4 + 2] = color.blue; rawData[(y * width + x) * 4 + 2] = color.blue;
} }
fun each(block : (x : Int, y : Int)->Unit) { fun each(block: (x: Int, y: Int)->Unit) {
for (x in 0..width - 1) { for (x in 0..width - 1) {
for (y in 0..height - 1) { for (y in 0..height - 1) {
block(x, y) block(x, y)
@@ -24,29 +24,28 @@ class Data(val rawData : Array<Int>, val width : Int, val height : Int) {
} }
} }
class Color(r : Int, g : Int, b : Int) : ColorLike { class Color(r: Int, g: Int, b: Int): ColorLike {
override val red: Int = r override val red: Int = r
override val green: Int = g override val green: Int = g
override val blue: Int = b override val blue: Int = b
} }
trait ColorLike { trait ColorLike {
val red : Int; val red: Int;
val green : Int; val green: Int;
val blue : Int; val blue: Int;
} }
fun box(): Boolean {
fun box() : Boolean {
val d = Data(Array(4) {0}, 1, 1) val d = Data(Array(4) {0}, 1, 1)
if (d[0, 0].red != 0) { if (d[0, 0].red != 0) {
return false return false
} }
if (d[0, 0].green != 0) { if (d[0, 0].green != 0) {
return false return false
} }
if (d[0, 0].blue != 0) { if (d[0, 0].blue != 0) {
return false return false
} }
return true return true
} }
@@ -5,31 +5,29 @@ var c1 = 0
var c2 = 0 var c2 = 0
class A() { class A() {
var p = 0 var p = 0
fun get(i : Int) : Int { fun get(i: Int): Int {
c1++ c1++
return 0 return 0
} }
fun set(i : Int, value : Int) {
c2++
}
fun set(i: Int, value: Int) {
c2++
}
} }
val a : A = A() val a: A = A()
get() { get() {
c0++ c0++
return $a return $a
} }
fun box() : String {
fun box(): String {
var d = a[1] var d = a[1]
if (c0 != 1) { if (c0 != 1) {
return "1" return "1"
} }
if (c1 != 1) { if (c1 != 1) {
return "2" return "2"
} }
++a[1] ++a[1]
@@ -37,20 +35,20 @@ fun box() : String {
return "3" return "3"
} }
if (c1 != 3) { if (c1 != 3) {
return "4" return "4"
} }
if (c2 != 1) { if (c2 != 1) {
return "5" return "5"
} }
--a[1] --a[1]
if (c0 != 3) { if (c0 != 3) {
return "6" return "6"
} }
if (c1 != 5) { if (c1 != 5) {
return "7" return "7"
} }
if (c2 != 2) { if (c2 != 2) {
return "8" return "8"
} }
return "OK" return "OK"
} }
@@ -1,7 +1,7 @@
class A(var a : Int) { class A(var a: Int) {
{ {
$a=3 $a = 3
} }
} }
fun box() = (A(1).a == 3) fun box() = (A(1).a == 3)
@@ -1,17 +1,18 @@
package foo package foo
class A() { class A() {
fun lold() = true
fun lold() = true val p = {{
lold()
val p = {{lold()}()} }()
}
} }
fun box(): Boolean {
fun box() : Boolean { return A().p()
return A().p()
} }
fun main(arg : Array<String>) { fun main(arg: Array<String>) {
println(box()) println(box())
} }
@@ -1,19 +1,18 @@
package foo package foo
class A() { class A() {
fun lold() = true
fun lold() = true val p: ()->Boolean
val p : ()->Boolean {
{ $p = {{lold()}()}
$p = {{lold()}()} }
}
} }
fun box() : Boolean { fun box(): Boolean {
return A().p() return A().p()
} }
fun main(arg : Array<String>) { fun main(arg: Array<String>) {
println(box()) println(box())
} }
@@ -1,18 +1,18 @@
package foo package foo
fun box() : Boolean { fun box(): Boolean {
if (t(1) != 0) { if (t(1) != 0) {
return false return false
} }
if (t(0) != 1) { if (t(0) != 1) {
return false return false
} }
return (t(100) == 2) return (t(100) == 2)
} }
fun t(i : Int) = when(i) { fun t(i: Int) = when(i) {
0 -> 1 0 -> 1
1 -> 0 1 -> 0
else -> 2 else -> 2
} }
@@ -1,7 +1,7 @@
package foo package foo
fun apply(i : Int, f : Int.(Int) -> Int) = i.f(1); fun apply(i: Int, f: Int.(Int) -> Int) = i.f(1);
fun box() : Boolean { fun box(): Boolean {
return (apply(1, {i -> i + this})) == 2 return apply(1, {i -> i + this}) == 2
} }
@@ -1,26 +1,24 @@
package foo package foo
class Foo { class Foo {
fun blah(value: Int): Int {
fun blah(value: Int): Int { return value + 1
return value + 1 }
}
} }
val Foo.fooImp : Int val Foo.fooImp: Int
get() { get() {
return blah(5) return blah(5)
} }
val Foo.fooExp : Int val Foo.fooExp: Int
get() { get() {
return this.blah(10) return this.blah(10)
} }
fun box() : Boolean { fun box(): Boolean {
var a = Foo() var a = Foo()
if (a.fooImp != 6) return false if (a.fooImp != 6) return false
if (a.fooExp != 11) return false if (a.fooExp != 11) return false
return true; return true;
} }
@@ -1,16 +1,16 @@
package foo package foo
open class A(var a : Int) { open class A(var a: Int) {
open fun Int.modify() : Int { open fun Int.modify(): Int {
return this * 3; return this * 3;
} }
fun eval() = a.modify(); fun eval() = a.modify();
} }
class B(a : Int) : A(a) { class B(a: Int): A(a) {
override fun Int.modify() : Int { override fun Int.modify(): Int {
return this - 2; return this - 2;
} }
} }
@@ -1,12 +1,12 @@
package foo package foo
open class C(a : Int) { open class C(a: Int) {
val b = a val b = a
} }
class D(c : Int) : C(c + 2) { class D(c: Int): C(c + 2) {
} }
fun box(): Boolean { fun box(): Boolean {
return (D(0).b == 2) return (D(0).b == 2)
} }
@@ -15,41 +15,41 @@
*/ */
{ {
var classes = function(){ var items = function () {
var A = Kotlin.createClass({initialize:function(){ var A = Kotlin.createClass({initialize: function () {
this.$order = ''; this.$order = '';
{ {
this.set_order(this.get_order() + 'A'); this.set_order(this.get_order() + 'A');
} }
}, set_order: function (tmp$0) {
this.$order = tmp$0;
}, get_order: function () {
return this.$order;
}
});
var B = Kotlin.createClass(A, {initialize: function () {
this.super_init();
{
this.set_order(this.get_order() + 'B');
}
}
});
var C = Kotlin.createClass(B, {initialize: function () {
this.super_init();
{
this.set_order(this.get_order() + 'C');
}
}
});
return {A: A, B: B, C: C};
} }
, set_order:function(tmp$0){ ();
this.$order = tmp$0;
} items.box = function () {
, get_order:function(){ return (new foo.C).get_order() === 'ABC' && (new foo.B).get_order() === 'AB' && (new foo.A).get_order() === 'A';
return this.$order; };
}
}); var foo = Kotlin.definePackage(items);
var B = Kotlin.createClass(A, {initialize:function(){
this.super_init();
{
this.set_order(this.get_order() + 'B');
}
}
});
var C = Kotlin.createClass(B, {initialize:function(){
this.super_init();
{
this.set_order(this.get_order() + 'C');
}
}
});
return {A:A, B:B, C:C};
}
();
var foo = Kotlin.definePackage(classes, {box:function(){
return (new foo.C).get_order() === 'ABC' && (new foo.B).get_order() === 'AB' && (new foo.A).get_order() === 'A';
}
});
} }
function test() { function test() {
@@ -4,17 +4,17 @@ import js.*
native native
class A(val c: Int) { class A(val c: Int) {
native native
class object { class object {
val g: Int = js.noImpl val g: Int = js.noImpl
val c: String = js.noImpl val c: String = js.noImpl
} }
} }
fun box(): Boolean { fun box(): Boolean {
if (A.g != 3) return false if (A.g != 3) return false
if (A.c != "hoooray") return false if (A.c != "hoooray") return false
if (A(2).c != 2) return false if (A(2).c != 2) return false
return true return true
} }
@@ -1,9 +1,7 @@
package foo package foo
class A() { class A() {
fun f(): Boolean {
fun f() : Boolean {
object t { object t {
val c = true; val c = true;
} }
@@ -12,7 +10,6 @@ class A() {
} }
return t.c && z.c return t.c && z.c
} }
} }
fun box() = A().f(); fun box() = A().f();
@@ -5,9 +5,7 @@ val a = object {
fun b() = 2 fun b() = 2
} }
fun box() : Boolean { fun box(): Boolean {
if (a.c() != 3) { if (a.c() != 3) {
return false; return false;
} }
@@ -15,6 +13,5 @@ fun box() : Boolean {
return false; return false;
} }
return true; return true;
} }
@@ -25,4 +25,4 @@ fun box():Boolean {
val test = _enumerate(Test()) val test = _enumerate(Test())
val p = _enumerate(P()) val p = _enumerate(P())
return (100 == test.a && "s" == test.b) && p.a == 100 && _findFirst<Int>(object {val test = 100}) == 100; return (100 == test.a && "s" == test.b) && p.a == 100 && _findFirst<Int>(object {val test = 100}) == 100;
} }
@@ -1,14 +1,19 @@
package foo package foo
trait I { trait I {
fun test():String fun test(): String
} }
class P : I { class P: I {
override fun test():String {return "a" + test("b")} override fun test(): String {
private fun test(p:String):String {return p} return "a" + test("b")
}
private fun test(p: String): String {
return p
}
} }
fun box():Boolean { fun box(): Boolean {
return P().test() == "ab" return P().test() == "ab"
} }
@@ -10,4 +10,4 @@ function _findFirst(o) {
for (var p in o) { for (var p in o) {
return o[p]; return o[p];
} }
} }
@@ -3,7 +3,7 @@ package foo
class Test() { class Test() {
} }
fun box() : Boolean { fun box(): Boolean {
var test = Test() var test = Test()
return true return true
} }
@@ -1,7 +1,7 @@
package foo package foo
val f = {(i : Int) -> i + 1} val f = {(i: Int) -> i + 1}
val a = Array(3, f) val a = Array(3, f)
fun box() = (a[0] == 1 && a[2] == 3 && a[1] == 2) fun box() = (a[0] == 1 && a[2] == 3 && a[1] == 2)
@@ -1,25 +1,25 @@
package foo package foo
trait A { trait A {
fun addFoo(s:String) : String { fun addFoo(s: String): String {
return s + "FOO" return s + "FOO"
} }
} }
trait B { trait B {
fun hooray() : String { fun hooray(): String {
return "hooray" return "hooray"
} }
} }
trait AD : A, B { trait AD: A, B {
} }
class Test() : AD { class Test(): AD {
fun eval() : String { fun eval(): String {
return addFoo(hooray()); return addFoo(hooray());
} }
} }
fun box() = (Test().eval() == "hoorayFOO") fun box() = (Test().eval() == "hoorayFOO")
@@ -134,8 +134,8 @@ class A() : BodyTag("a") {
} }
} }
fun html(init : HTML.() -> Unit) : HTML { fun html(init: HTML.() -> Unit): HTML {
val html = HTML() val html = HTML()
html.init() html.init()
return html return html
} }