From f0f94eda6f8d2d09d6597e3b4579ebc6fdf3d3f4 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Thu, 21 Feb 2019 00:01:03 +0100 Subject: [PATCH] Fix #581: Add tests and adapt to named-base unapplySeq spec --- tests/pending/run/value-class-extractor-seq.check | 3 --- tests/{pending => }/run/string-extractor.check | 0 tests/{pending => }/run/string-extractor.scala | 14 ++++++++------ tests/run/value-class-extractor-seq.check | 3 +++ .../run/value-class-extractor-seq.scala | 8 ++++++-- 5 files changed, 17 insertions(+), 11 deletions(-) delete mode 100644 tests/pending/run/value-class-extractor-seq.check rename tests/{pending => }/run/string-extractor.check (100%) rename tests/{pending => }/run/string-extractor.scala (76%) create mode 100644 tests/run/value-class-extractor-seq.check rename tests/{pending => }/run/value-class-extractor-seq.scala (88%) diff --git a/tests/pending/run/value-class-extractor-seq.check b/tests/pending/run/value-class-extractor-seq.check deleted file mode 100644 index 84552a7aa5b2..000000000000 --- a/tests/pending/run/value-class-extractor-seq.check +++ /dev/null @@ -1,3 +0,0 @@ -Bip(1, 2, 3) -Bip(1, 2, c @ Array(3, 4, 5): _*) -class [I diff --git a/tests/pending/run/string-extractor.check b/tests/run/string-extractor.check similarity index 100% rename from tests/pending/run/string-extractor.check rename to tests/run/string-extractor.check diff --git a/tests/pending/run/string-extractor.scala b/tests/run/string-extractor.scala similarity index 76% rename from tests/pending/run/string-extractor.scala rename to tests/run/string-extractor.scala index 7ab2c2eaab29..ab6a8a14a125 100644 --- a/tests/pending/run/string-extractor.scala +++ b/tests/run/string-extractor.scala @@ -1,12 +1,13 @@ final class StringExtract(val s: String) extends AnyVal { def isEmpty = (s eq null) || (s == "") + def toSeq: Seq[Char] = s def get = this def length = s.length def lengthCompare(n: Int) = s.length compare n def apply(idx: Int): Char = s charAt idx def head: Char = s charAt 0 def tail: String = s drop 1 - def drop(n: Int): StringExtract = new StringExtract(s drop n) + def drop(n: Int): Seq[Char] = s drop n override def toString = s } @@ -19,7 +20,8 @@ final class ThreeStringExtract(val s: String) extends AnyVal { def apply(idx: Int): Char = s charAt idx def head: Char = s charAt 0 def tail: String = s drop 1 - def drop(n: Int): ThreeStringExtract = new ThreeStringExtract(s drop n) + def toSeq: Seq[Char] = s + def drop(n: Int): Seq[Char] = s drop n override def toString = s } @@ -29,7 +31,7 @@ object Bippy { def unapplySeq(x: Any): StringExtract = new StringExtract("" + x) } object TripleBippy { - def unapplySeq(x: Any): ThreeStringExtract = new ThreeStringExtract("" + x) + def unapply(x: Any): ThreeStringExtract = new ThreeStringExtract("" + x) } object Test { @@ -39,9 +41,9 @@ object Test { } def g(x: Any): String = x match { - case TripleBippy(3 :: Nil, 3.0, 'b', chars : _*) => "1: " + chars - case TripleBippy(5 :: Nil, 5.0, 'b' | 'B', chars : _*) => "2: " + chars - case TripleBippy(_, _, chars : _*) => "3: " + chars + case TripleBippy(3 :: Nil, 3.0, Bippy('b', chars : _*)) => "1: " + chars + case TripleBippy(5 :: Nil, 5.0, Bippy('b' | 'B', chars : _*)) => "2: " + chars + case TripleBippy(_, _, Bippy(chars : _*)) => "3: " + chars case _ => "nope" } diff --git a/tests/run/value-class-extractor-seq.check b/tests/run/value-class-extractor-seq.check new file mode 100644 index 000000000000..79cc4989ee9d --- /dev/null +++ b/tests/run/value-class-extractor-seq.check @@ -0,0 +1,3 @@ +Bip(1, 2, 3) +Bip(1, 2, c @ WrappedArray(3, 4, 5): _*) +class [I diff --git a/tests/pending/run/value-class-extractor-seq.scala b/tests/run/value-class-extractor-seq.scala similarity index 88% rename from tests/pending/run/value-class-extractor-seq.scala rename to tests/run/value-class-extractor-seq.scala index 9264e70387d0..f49a4c8a2f63 100644 --- a/tests/pending/run/value-class-extractor-seq.scala +++ b/tests/run/value-class-extractor-seq.scala @@ -1,8 +1,12 @@ import scala.runtime.ScalaRunTime.stringOf final class ArrayOpt[T](val xs: Array[T]) extends AnyVal { + def toSeq: Seq[T] = xs.toSeq + def length: Int = xs.length def isEmpty = xs == null - def get = xs + def get = this + def apply(i: Int) = xs(i) + def drop(i: Int): Seq[T] = xs.drop(i) } object Bip { @@ -44,7 +48,7 @@ object Bip { object Test { def f(x: Any) = x match { case Bip(a, b, c) => s"Bip($a, $b, $c)" - case Bip(a, b, c : _*) => s"Bip($a, $b, c @ ${stringOf(c)}: _*)" + case Bip(a, b, c: _*) => s"Bip($a, $b, c @ ${stringOf(c)}: _*)" case _ => "" + x.getClass }