Skip to content

Commit

Permalink
Merge branch 'dev-natives-to-wollok' of github.com:uqbar-project/woll…
Browse files Browse the repository at this point in the history
…ok into dev-natives-to-wollok
  • Loading branch information
javierfernandes committed Nov 14, 2015
2 parents 49ac673 + 6f3af86 commit 4c70f00
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
27 changes: 23 additions & 4 deletions org.uqbar.project.wollok.lib/src/wollok.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ package lang {
}
method getX() { return x }
method getY() { return y }
method getKey() { this.getX() }
method getValue() { this.getY() }
method getKey() { return this.getX() }
method getValue() { return this.getY() }
}

class Collection {
Expand Down Expand Up @@ -210,6 +210,8 @@ package lang {

method toStringPrefix()
method toStringSufix()
method asList()
method asSet()

method newInstance()
}
Expand All @@ -221,10 +223,18 @@ package lang {
*/
class Set extends Collection {

override method newInstance() = new Set()
override method newInstance() = #{}
override method toStringPrefix() = "#{"
override method toStringSufix() = "}"

override method asList() {
val result = #[]
result.addAll(this)
return result
}

override method asSet() = this

method any() = this.first()

method first() native
Expand All @@ -250,7 +260,7 @@ package lang {

method get(index) native

override method newInstance() = new List()
override method newInstance() = #[]

method any() {
if (this.isEmpty())
Expand All @@ -261,6 +271,15 @@ package lang {

override method toStringPrefix() = "#["
override method toStringSufix() = "]"

override method asList() = this

override method asSet() {
val result = #{}
result.addAll(this)
return result
}


// REFACTORME: DUP METHODS
method fold(initialValue, closure) native
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.uqbar.project.wollok.tests.interpreter.collections
package org.uqbar.project.wollok.tests.sdk

import org.junit.Test
import org.uqbar.project.wollok.tests.interpreter.AbstractWollokInterpreterTestCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class ListTest extends ListTestCase {
@Test
def void testContainsWithComplexObjects() {
'''
object o1 {}
object o2 {}
object o1 {}
object o2 {}
program p {
val list = #[o1, o2]
Expand All @@ -60,5 +60,14 @@ class ListTest extends ListTestCase {
}'''.interpretPropagatingErrors
}


@Test
def void testConversions() {
'''
program p {
val list = #[1,2,3]
assert.equals(#[1,2,3], list.asList())
assert.equals(#{1,2,3}, list.asSet())
}'''.interpretPropagatingErrors
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.uqbar.project.wollok.tests.interpreter.collections
package org.uqbar.project.wollok.tests.sdk

import org.junit.Test
import org.uqbar.project.wollok.tests.interpreter.ListTestCase
Expand Down Expand Up @@ -67,4 +67,16 @@ class SetTest extends ListTestCase {
}'''.interpretPropagatingErrors
}

}
@Test
def void testConversions() {
'''
program p {
val set= #{1,2,3}
assert.equals(#{1,2,3}, set.asSet())
val list = set.asList()
assert.equals(3, list.size())
#[1,2,3].forEach[i|assert.equals(list.contains(i))]
}'''.interpretPropagatingErrors
}
}

0 comments on commit 4c70f00

Please sign in to comment.