1/*
2 * Copyright 2001-2008 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 */
16package org.scalatest
17
18import events.InfoProvided
19import org.scalatest.matchers.ShouldMatchers
20
21class EngineSpec extends FlatSpec with SharedHelpers with ShouldMatchers {
22
23  "EngineSpec.getTestNamePrefix" should "return empty string for Trunk" in {
24    val engine = new Engine("concurrentFunSuiteBundleMod", "FunSuite")
25    import engine._
26    getTestNamePrefix(Trunk) should be ("")
27  }
28
29  it should "return empty string for direct children of Trunk" in {
30    val engine = new Engine("concurrentFunSuiteBundleMod", "FunSuite")
31    import engine._
32    val child = DescriptionBranch(Trunk, "Catherine", Some("child prefix"))
33    Trunk.subNodes ::= child
34    getTestNamePrefix(child) should be ("Catherine child prefix")
35  }
36
37  it should "return the parent's description name for DescriptionBranch grandchildren of trunk" in {
38    val engine = new Engine("concurrentFunSuiteBundleMod", "FunSuite")
39    import engine._
40    val child = DescriptionBranch(Trunk, "child", Some("child prefix"))
41    Trunk.subNodes ::= child
42    val grandchild = DescriptionBranch(child, "grandchild", None)
43    child.subNodes ::= grandchild
44    getTestNamePrefix(grandchild) should be ("child child prefix grandchild")
45  }
46
47  "EngineSpec.getTestName" should "return the prefix, a space, and the testText" in {
48    val engine = new Engine("concurrentFunSuiteBundleMod", "FunSuite")
49    import engine._
50    val child = DescriptionBranch(Trunk, "child", Some("child prefix"))
51    Trunk.subNodes ::= child
52    val grandchild = DescriptionBranch(child, "grandchild", None)
53    child.subNodes ::= grandchild
54    getTestName("howdy there", grandchild) should be ("child child prefix grandchild howdy there")
55  }
56  "EngineSpec.getIndentationLevelForNode" should "return the indentation level for a test" in {
57    val engine = new Engine("concurrentFunSuiteBundleMod", "FunSuite")
58    import engine._
59    val child = DescriptionBranch(Trunk, "child", Some("child prefix"))
60    Trunk.subNodes ::= child
61    val childTest = TestLeaf(Trunk, "child test", "child test", () => ())
62    Trunk.subNodes ::= childTest
63    val grandchild = DescriptionBranch(child, "grandchild", None)
64    child.subNodes ::= grandchild
65    val grandchildTest = TestLeaf(child, "grandchild test", "grandchild test", () => ())
66    child.subNodes ::= grandchildTest
67    val greatGrandchildTest = TestLeaf(grandchild, "great-grandchild test", "great-grandchild test", () => ())
68    grandchild.subNodes ::= greatGrandchildTest
69    Trunk.indentationLevel should be (0)
70    child.indentationLevel should be (0)
71    childTest.indentationLevel should be (0)
72    grandchild.indentationLevel should be (1)
73    grandchildTest.indentationLevel should be (1)
74    greatGrandchildTest.indentationLevel should be (2)
75  }
76}
77