Skip to content

Commit d724f93

Browse files
committed
Ported over code form pretty-differ-2 branch, tests passed.
1 parent 3837f67 commit d724f93

File tree

18 files changed

+1382
-48
lines changed

18 files changed

+1382
-48
lines changed

project/GenScalacticJS.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ object GenScalacticJS {
8282
def genScala(targetDir: File, version: String, scalaVersion: String): Seq[File] =
8383
copyDir("scalactic/src/main/scala/org/scalactic", "org/scalactic", targetDir, List.empty) ++
8484
copyDir("scalactic/src/main/scala/org/scalactic/exceptions", "org/scalactic/exceptions", targetDir, List.empty) ++
85-
copyDir("scalactic/src/main/scala/org/scalactic/source", "org/scalactic/source", targetDir, List.empty) ++
86-
copyDir("scalactic/src/main/scala/org/scalactic/anyvals", "org/scalactic/anyvals", targetDir, List.empty) ++
85+
copyDir("scalactic/src/main/scala/org/scalactic/source", "org/scalactic/source", targetDir, List("ObjectMeta.scala")) ++
86+
copyDir("scalactic/src/main/scala/org/scalactic/anyvals", "org/scalactic/anyvals", targetDir, List.empty) ++
8787
GenVersions.genScalacticVersions(new File(targetDir, "org/scalactic"), version, scalaVersion)
8888

8989
def genMacroScala(targetDir: File, version: String, scalaVersion: String): Seq[File] =

scalactic-test/src/test/scala/org/scalactic/DifferSpec.scala

Lines changed: 604 additions & 0 deletions
Large diffs are not rendered by default.

scalactic-test/src/test/scala/org/scalactic/PrettifierSpec.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class PrettifierSpec extends FunSpec with Matchers {
6565
case _ => Prettifier.default(o)
6666
}
6767
}
68-
myLittlePretty(Yell("I like fruit loops"), Yell("I like raisin bran")) shouldBe PrettyPair("I LIKE FRUIT LOOPS!!!", "I LIKE RAISIN BRAN!!!", None)
68+
val left = Yell("I like fruit loops")
69+
myLittlePretty(left, Yell("I like raisin bran")) shouldBe PrettyPair("I LIKE FRUIT LOOPS!!!", "I LIKE RAISIN BRAN!!!", Some(Differ.simpleClassName(left) + "(secret: \"I like [fruit loops]\" -> \"I like [raisin bran]\")"))
6970
}
7071
}
7172

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright 2001-2016 Artima, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.scalactic.source
17+
18+
trait ObjectMeta {
19+
20+
def fieldNames: scala.collection.immutable.IndexedSeq[String]
21+
22+
def hasField(name: String): Boolean = fieldNames.contains(name)
23+
24+
def value(name: String): Any
25+
26+
def typeName(name: String): String
27+
28+
def shortTypeName(name: String): String
29+
30+
}
31+
32+
object ObjectMeta {
33+
34+
def apply(v: Any): ObjectMeta = {
35+
36+
def filterDollarNumberAtTheEnd(value: String): String = {
37+
val lastIdxOfDollar = value.lastIndexOf('$')
38+
if (lastIdxOfDollar > 0) {
39+
val afterDollar = value.substring(lastIdxOfDollar + 1)
40+
try {
41+
afterDollar.toInt
42+
value.substring(0, lastIdxOfDollar)
43+
}
44+
catch {
45+
case t: Throwable => value
46+
}
47+
}
48+
else
49+
value
50+
}
51+
52+
val dict = v.asInstanceOf[scala.scalajs.js.Dictionary[Any]].flatMap { case (key, value) =>
53+
val decodedKey =
54+
scala.reflect.NameTransformer.decode(key).
55+
replaceAllLiterally("$$und", "_").
56+
replaceAllLiterally("$mcI", "").
57+
replaceAllLiterally("$sp", "").
58+
replaceAllLiterally("$f", "")
59+
60+
Some((filterDollarNumberAtTheEnd(decodedKey), value))
61+
}
62+
63+
new ObjectMeta {
64+
65+
lazy val fieldNames = dict.keys.toVector.filter(_ != "$$outer")
66+
67+
def value(name: String): Any = {
68+
dict.get(name) match {
69+
case Some(value) => value
70+
case None => throw new IllegalArgumentException("'" + name + "' is not attribute for this instance.")
71+
}
72+
}
73+
74+
def typeName(name: String): String = {
75+
dict.get(name) match {
76+
case Some(value) => value.getClass.getName
77+
case None => throw new IllegalArgumentException("'" + name + "' is not attribute for this instance.")
78+
}
79+
}
80+
81+
def shortTypeName(name: String): String = {
82+
dict.get(name) match {
83+
case Some(value) => value.getClass.getSimpleName
84+
case None => throw new IllegalArgumentException("'" + name + "' is not attribute for this instance.")
85+
}
86+
}
87+
}
88+
}
89+
90+
}

0 commit comments

Comments
 (0)