Skip to content

Commit 9927ced

Browse files
committed
first ruff draft for automated unapply
1 parent 7e036e8 commit 9927ced

File tree

9 files changed

+224
-187
lines changed

9 files changed

+224
-187
lines changed

extension/.js/src/test/scala/jstengel/ezxml/extension/AnnotatedExampleClasses.scala

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,27 +81,27 @@ object AnnotatedExampleClasses {
8181
// }
8282
// }
8383

84-
@Xml class AnnotatedStrangeIterator(val id: String, it: List[(Int, Int)]) extends Iterable[(Int, Int)] {
85-
override val iterator : Iterator[(Int, Int)] = it.iterator
86-
override def equals (obj : Any) : Boolean = obj match {
87-
case other: AnnotatedStrangeIterator => iterator.toList == other.iterator.toList && id == other.id
88-
}
89-
override def toString : String = s"AnnotatedStrangeIterator($id, $it)"
90-
}
91-
92-
@Xml class AnnotatedIntList(val i: Int*) extends Iterable[Int] {
93-
override def iterator : Iterator[Int] = i.iterator
94-
override def equals (obj : Any) : Boolean = obj match {
95-
case other: AnnotatedIntList => iterator.toList == other.iterator.toList
96-
}
97-
}
98-
99-
@Xml class AnnotatedPrivateConstructorTest private (val a : Int*) {
100-
def this(b: Int) = this(b, b)
101-
override def equals (obj : Any) : Boolean = obj match {
102-
case other: AnnotatedPrivateConstructorTest => a == other.a
103-
}
104-
override def toString : String = s"PrivateConstructorTest(${a.mkString(", ")})"
105-
}
84+
// @Xml class AnnotatedStrangeIterator(val id: String, it: List[(Int, Int)]) extends Iterable[(Int, Int)] {
85+
// override val iterator : Iterator[(Int, Int)] = it.iterator
86+
// override def equals (obj : Any) : Boolean = obj match {
87+
// case other: AnnotatedStrangeIterator => iterator.toList == other.iterator.toList && id == other.id
88+
// }
89+
// override def toString : String = s"AnnotatedStrangeIterator($id, $it)"
90+
// }
91+
//
92+
// @Xml class AnnotatedIntList(val i: Int*) extends Iterable[Int] {
93+
// override def iterator : Iterator[Int] = i.iterator
94+
// override def equals (obj : Any) : Boolean = obj match {
95+
// case other: AnnotatedIntList => iterator.toList == other.iterator.toList
96+
// }
97+
// }
98+
//
99+
// @Xml class AnnotatedPrivateConstructorTest private (val a : Int*) {
100+
// def this(b: Int) = this(b, b)
101+
// override def equals (obj : Any) : Boolean = obj match {
102+
// case other: AnnotatedPrivateConstructorTest => a == other.a
103+
// }
104+
// override def toString : String = s"PrivateConstructorTest(${a.mkString(", ")})"
105+
// }
106106

107107
}

extension/.js/src/test/scala/jstengel/ezxml/extension/ct/CTLoadingTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class CTLoadingTest extends AnyFlatSpec {
115115
val emptyTupleList: List[(Int, String)] = List()
116116
test(emptyTupleList, xmlMacro[List[(Int, String)]], obj[List[(Int, String)]])
117117

118-
test(new AnnotatedIntList(1, 2, 3, 4, 5, 6), xmlMacro[AnnotatedIntList], obj[AnnotatedIntList])
118+
// test(new AnnotatedIntList(1, 2, 3, 4, 5, 6), xmlMacro[AnnotatedIntList], obj[AnnotatedIntList])
119119
test(new StrangeIterator("testID", List((1, 2), (3, 4), (5, 6))), xmlMacro[StrangeIterator], obj[StrangeIterator])
120120

121121
test(RTSpecialTypeParameterTestClass1(1, "test", 2, 4.56),

extension/.jvm/src/test/scala/jstengel/ezxml/extension/AnnotatedExampleClasses.scala

Lines changed: 57 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ object AnnotatedExampleClasses {
4949
// override def encode : Elem = CtEncoder.xmlMacro[CTSpecialTypeParameterTestClass2[T1, T2]](this)
5050
// }
5151

52-
@Xml class AnnotatedStrangeIterator(val id: String, it: List[(Int, Int)]) extends Iterable[(Int, Int)] {
53-
override val iterator : Iterator[(Int, Int)] = it.iterator
54-
override def equals (obj : Any) : Boolean = obj match {
55-
case other: AnnotatedStrangeIterator => iterator.toList == other.iterator.toList && id == other.id
56-
}
57-
override def toString : String = s"AnnotatedStrangeIterator($id, $it)"
58-
}
52+
// TODO enable when extractor is finished.
53+
// @Xml class AnnotatedStrangeIterator(val id: String, it: List[(Int, Int)]) extends Iterable[(Int, Int)] {
54+
// override val iterator : Iterator[(Int, Int)] = it.iterator
55+
// override def equals (obj : Any) : Boolean = obj match {
56+
// case other: AnnotatedStrangeIterator => iterator.toList == other.iterator.toList && id == other.id
57+
// }
58+
// override def toString : String = s"AnnotatedStrangeIterator($id, $it)"
59+
// }
5960

6061

6162

@@ -88,54 +89,56 @@ object AnnotatedExampleClasses {
8889
// override def equals (obj : Any) : Boolean = obj match {
8990
// case nct: NonCaseRuntTimeTestWithExtension => bla == nct.bla && blue == nct.blue && im == nct.im
9091
// }
92+
// }
93+
94+
// TODO enable when extractor is finished.
95+
// trait IntSet {
96+
// def incl(x: Int): IntSet
97+
// def contains(x: Int): Boolean
98+
// def union(other: IntSet): IntSet
99+
// }
100+
// object EmptyIntSet extends IntSet {
101+
// def contains(x: Int): Boolean = false
102+
// def incl(x: Int): IntSet = new NonEmpty(x, EmptyIntSet, EmptyIntSet)
103+
// def union(other: IntSet): IntSet = other
104+
// override def equals (obj : Any) : Boolean = obj == EmptyIntSet
105+
// override def toString = "."
106+
// }
107+
// @Xml class NonEmpty(elem : Int, left : IntSet, right : IntSet) extends IntSet {
108+
//
109+
// def contains (x : Int) : Boolean =
110+
// if ( x < elem ) left contains x
111+
// else if ( x > elem ) right contains x
112+
// else true
113+
//
114+
// def incl (x : Int) : IntSet =
115+
// if ( x < elem ) new NonEmpty(elem, left incl x, right)
116+
// else if ( x > elem ) new NonEmpty(elem, left, right incl x)
117+
// else this
118+
//
119+
// def union (other : IntSet) : IntSet =
120+
// ( ( left union right ) union other ) incl elem
121+
//
122+
// override def equals (obj : Any) : Boolean = obj.toString == toString
123+
//
124+
// override def toString : String = "{" + left + elem + right + "}"
125+
//
91126
// }
92127

93-
trait IntSet {
94-
def incl(x: Int): IntSet
95-
def contains(x: Int): Boolean
96-
def union(other: IntSet): IntSet
97-
}
98-
object EmptyIntSet extends IntSet {
99-
def contains(x: Int): Boolean = false
100-
def incl(x: Int): IntSet = new NonEmpty(x, EmptyIntSet, EmptyIntSet)
101-
def union(other: IntSet): IntSet = other
102-
override def equals (obj : Any) : Boolean = obj == EmptyIntSet
103-
override def toString = "."
104-
}
105-
@Xml class NonEmpty(elem : Int, left : IntSet, right : IntSet) extends IntSet {
106-
107-
def contains (x : Int) : Boolean =
108-
if ( x < elem ) left contains x
109-
else if ( x > elem ) right contains x
110-
else true
111-
112-
def incl (x : Int) : IntSet =
113-
if ( x < elem ) new NonEmpty(elem, left incl x, right)
114-
else if ( x > elem ) new NonEmpty(elem, left, right incl x)
115-
else this
116-
117-
def union (other : IntSet) : IntSet =
118-
( ( left union right ) union other ) incl elem
119-
120-
override def equals (obj : Any) : Boolean = obj.toString == toString
121-
122-
override def toString : String = "{" + left + elem + right + "}"
123-
124-
}
125-
126-
@Xml class AnnotatedIntList(val i: Int*) extends Iterable[Int] {
127-
override def iterator : Iterator[Int] = i.iterator
128-
override def equals (obj : Any) : Boolean = obj match {
129-
case other: AnnotatedIntList => iterator.toList == other.iterator.toList
130-
}
131-
}
132-
133-
@Xml class AnnotatedPrivateConstructorTest private (val a : Int*) {
134-
def this(b: Int) = this(b, b)
135-
override def equals (obj : Any) : Boolean = obj match {
136-
case other: AnnotatedPrivateConstructorTest => a == other.a
137-
}
138-
override def toString : String = s"PrivateConstructorTest(${a.mkString(", ")})"
139-
}
128+
// TODO enable when extractor is finished. Still needs to be converted to Seq
129+
// @Xml class AnnotatedIntList(val i: Int*) extends Iterable[Int] {
130+
// override def iterator : Iterator[Int] = i.iterator
131+
// override def equals (obj : Any) : Boolean = obj match {
132+
// case other: AnnotatedIntList => iterator.toList == other.iterator.toList
133+
// }
134+
// }
135+
// TODO enable when extractor is finished.
136+
// @Xml class AnnotatedPrivateConstructorTest private (val a : Int*) {
137+
// def this(b: Int) = this(b, b)
138+
// override def equals (obj : Any) : Boolean = obj match {
139+
// case other: AnnotatedPrivateConstructorTest => a == other.a
140+
// }
141+
// override def toString : String = s"PrivateConstructorTest(${a.mkString(", ")})"
142+
// }
140143

141144
}

extension/src/test/scala/jstengel/ezxml/extension/QuickTest.scala renamed to extension/.jvm/src/test/scala/jstengel/ezxml/extension/QuickTest.scala

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,16 @@ object QuickTest extends App {
4949
// println(reverseMap.xml.obj[Map[String, String]].get)
5050

5151

52-
// "testInput" match {
53-
// case extractor(_, _, s) => println(s)
54-
// }
55-
//
56-
// new Testclass("bla").encode() match {
57-
// case Testclass(s) => println(s)
58-
// case _ =>
59-
// }
60-
//
52+
"testInput" match {
53+
case extractor(_, _, s) => println(s)
54+
case _ =>
55+
}
56+
57+
new TestClass("bla").encode() match {
58+
case TestClass(in) => println(in)
59+
case _ =>
60+
}
61+
6162
// ExtractionTest("test", 1, 2) match {
6263
// case ExtractionTest(a, b, c) => println(c)
6364
// case _ =>
@@ -79,19 +80,6 @@ object extractor {
7980

8081
}
8182

82-
@Xml class Testclass(a: String) extends XmlClassTrait {
83+
@Xml class TestClass (val a : String) extends XmlClassTrait {
8384
def encode(): Elem = ???
84-
}
85-
object Testclass extends XmlObjectTrait {
86-
override def decode (elem : Elem) : Testclass = ???
87-
88-
def unapply (arg : Testclass) : Option[String] = Some("a")
89-
90-
// def unapply(xml: Elem): Option[String] = {
91-
// Some("a")
92-
//// if (xml.label.contains("Testclass")) {
93-
//// ExtractorMacro.extractor[Testclass, String](decode(xml))
94-
//// } else
95-
//// None
96-
// }
9785
}

extension/.jvm/src/test/scala/jstengel/ezxml/extension/ct/CTLoadingTest.scala

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,20 @@ class CTLoadingTest extends AnyFlatSpec {
9595
test(Tuple1(3), xmlMacro[Tuple1[Int]], obj[Tuple1[Int]])
9696
test(Tuple1(applyTest), xmlMacro[Tuple1[TestTrait]], obj[Tuple1[TestTrait]])
9797
test(Some(3): Option[Int], xmlMacro[Option[Int]], obj[Option[Int]])
98-
99-
val tree = new NonEmpty(4,
100-
new NonEmpty(6,
101-
new NonEmpty(19,
102-
EmptyIntSet,
103-
EmptyIntSet),
104-
new NonEmpty(90,
105-
EmptyIntSet,
106-
EmptyIntSet)),
107-
new NonEmpty(13,
108-
EmptyIntSet,
109-
EmptyIntSet))
110-
test(tree, xmlMacro[IntSet], obj[IntSet])
98+
99+
// TODO enable when extractor is finished.
100+
// val tree = new NonEmpty(4,
101+
// new NonEmpty(6,
102+
// new NonEmpty(19,
103+
// EmptyIntSet,
104+
// EmptyIntSet),
105+
// new NonEmpty(90,
106+
// EmptyIntSet,
107+
// EmptyIntSet)),
108+
// new NonEmpty(13,
109+
// EmptyIntSet,
110+
// EmptyIntSet))
111+
// test(tree, xmlMacro[IntSet], obj[IntSet])
111112

112113
test(ccNonIterIntList(1, 2, 3, 4, 5), xmlMacro[ccNonIterIntList], obj[ccNonIterIntList])
113114
test(new nonIterIntList(1, 2, 3, 4, 5, 6), xmlMacro[nonIterIntList], obj[nonIterIntList])
@@ -138,12 +139,14 @@ class CTLoadingTest extends AnyFlatSpec {
138139
test(tupleList, xmlMacro[List[(Int, String)]], obj[List[(Int, String)]])
139140
val emptyTupleList: List[(Int, String)] = List()
140141
test(emptyTupleList, xmlMacro[List[(Int, String)]], obj[List[(Int, String)]])
141-
142-
test(new AnnotatedIntList(1, 2, 3, 4, 5, 6), xmlMacro[AnnotatedIntList], obj[AnnotatedIntList])
142+
143+
// TODO enable when extractor is finished.
144+
// test(new AnnotatedIntList(1, 2, 3, 4, 5, 6), xmlMacro[AnnotatedIntList], obj[AnnotatedIntList])
143145
test(new StrangeIterator("testID", List((1, 2), (3, 4), (5, 6))), xmlMacro[StrangeIterator], obj[StrangeIterator])
144-
145-
val annotatedIt = new AnnotatedStrangeIterator("testID", List((1, 2), (3, 4), (5, 6)))
146-
test(annotatedIt, xml(annotatedIt), obj[AnnotatedStrangeIterator])
146+
147+
// TODO enable when extractor is finished.
148+
// val annotatedIt = new AnnotatedStrangeIterator("testID", List((1, 2), (3, 4), (5, 6)))
149+
// test(annotatedIt, xml(annotatedIt), obj[AnnotatedStrangeIterator])
147150

148151
test(RTSpecialTypeParameterTestClass1(1, "test", 2, 4.56),
149152
xmlMacro[RTSpecialTypeParameterTestClass1[Int, String, Double]],

extension/.jvm/src/test/scala/jstengel/ezxml/extension/ct/CompleteAnnotationExample.scala

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,36 @@ import jstengel.ezxml.core.SimpleWrapper.NodeWrapper
44
import jstengel.ezxml.extension.XmlClassTrait
55
import jstengel.ezxml.extension.ct.CtDecoder.obj
66

7-
class BaseClass(val a: String)
8-
9-
case class ChildClass(override val a : String) extends BaseClass(a)
10-
11-
@Xml class CompleteAnnotationExample (val s : String,
12-
@RuntimeXML val b : BaseClass,
13-
c1 : Int) {
14-
15-
@CacheXML private[ct] val someHardCalculation: Int = {
16-
// if you look at the output, you will notice that the intermediary steps are missing
17-
// and only the result gets loaded
18-
println("calculated")
19-
println("calculated2")
20-
println("calculated3")
21-
1
22-
}
23-
@CacheXML val someHardCalculation2: Int = 2
24-
25-
@CacheXML @RuntimeXML val baseClass: BaseClass = ChildClass("test")
26-
27-
}
28-
29-
object ExampleTest extends App {
30-
31-
val original = new CompleteAnnotationExample("testString", ChildClass("ImplementedClass-output"), 1414)
32-
val x = original.asInstanceOf[XmlClassTrait].encode
33-
println(x.toPrettyXMLString)
34-
val decoded = obj[CompleteAnnotationExample](x)
35-
println(decoded.someHardCalculation)
36-
println(decoded.someHardCalculation2)
37-
println(decoded.baseClass)
38-
39-
}
7+
//class BaseClass(val a: String)
8+
//
9+
//case class ChildClass(override val a : String) extends BaseClass(a)
10+
//
11+
//@Xml class CompleteAnnotationExample (val s : String,
12+
// @RuntimeXML val b : BaseClass,
13+
// c1 : Int) {
14+
//
15+
// @CacheXML private[ct] val someHardCalculation: Int = {
16+
// // if you look at the output, you will notice that the intermediary steps are missing
17+
// // and only the result gets loaded
18+
// println("calculated")
19+
// println("calculated2")
20+
// println("calculated3")
21+
// 1
22+
// }
23+
// @CacheXML val someHardCalculation2: Int = 2
24+
//
25+
// @CacheXML @RuntimeXML val baseClass: BaseClass = ChildClass("test")
26+
//
27+
//}
28+
//
29+
//object ExampleTest extends App {
30+
//
31+
// val original = new CompleteAnnotationExample("testString", ChildClass("ImplementedClass-output"), 1414)
32+
// val x = original.asInstanceOf[XmlClassTrait].encode
33+
// println(x.toPrettyXMLString)
34+
// val decoded = obj[CompleteAnnotationExample](x)
35+
// println(decoded.someHardCalculation)
36+
// println(decoded.someHardCalculation2)
37+
// println(decoded.baseClass)
38+
//
39+
//}

0 commit comments

Comments
 (0)