Skip to content

Commit cefd4c8

Browse files
authored
Coverage fix (#93)
* Coverage fix
1 parent a7e021b commit cefd4c8

File tree

7 files changed

+185
-26
lines changed

7 files changed

+185
-26
lines changed

.github/badges/branches.svg

Lines changed: 1 addition & 1 deletion
Loading

.github/badges/jacoco.svg

Lines changed: 1 addition & 1 deletion
Loading

src/main/kotlin/org/xpathqs/core/selector/group/GroupSelectorModificationExtensions.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ fun <T : GroupSelector> T.tag(value: String): T {
4747

4848
/**
4949
* Modifies `prefix` value of [GroupSelector]
50+
*
51+
* Require #1 - Prefix should be updated only when [GroupSelector.selectorsChain]
52+
* has first [Selector] element. It is actual for the Block elements
53+
* @sample [org.xpathqs.core.selector.group.extensions.PrefixTest.r1_prefixWithSelector]
54+
*
55+
* Require #2 - prefix should be ignored when first selector is not a [Selector] object
56+
* @sample [org.xpathqs.core.selector.group.extensions.PrefixTest.r2_prefixWithXpathSelector]
5057
*/
5158
fun <T : GroupSelector> T.prefix(value: String): T {
5259
val first = this.selectorsChain.first()
@@ -63,7 +70,13 @@ fun <T : GroupSelector> T.prefix(value: String): T {
6370
}
6471

6572
/**
66-
* Modifies `tag` value of [GroupSelector]
73+
* Add an argument to the group
74+
*
75+
* Require #1 - when there is only one element then [arg] should be added to that element directly
76+
* @sample [org.xpathqs.core.selector.group.extensions.AddGroupArgTest.r1_singleSelector]
77+
*
78+
* Require #2 - when there is more than one element than [arg] should be added to the self
79+
* @sample [org.xpathqs.core.selector.group.extensions.AddGroupArgTest.r2_multipleSelector]
6780
*/
6881
fun <T : GroupSelector> T.addGroupArg(arg: ValueArg): T {
6982
val res = this.clone()
@@ -76,15 +89,4 @@ fun <T : GroupSelector> T.addGroupArg(arg: ValueArg): T {
7689
)
7790
}
7891
return res
79-
}
80-
81-
/**
82-
* Add new selector to the [GroupSelector.selectorsChain]
83-
*/
84-
operator fun <T : GroupSelector> T.plus(sel: BaseSelector): T {
85-
val res = this.clone()
86-
res.add(
87-
sel.clone()
88-
)
89-
return res
9092
}

src/test/kotlin/org/xpathqs/core/selector/base/extension/SelectorParametersTest.kt

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,102 +39,106 @@ class SelectorParametersTest {
3939
* @see [org.xpathqs.core.selector.extensions.contains]
4040
*/
4141
@Test
42-
fun r1_contains() =
42+
fun r1_contains() {
4343
WHEN {
4444
tagSelector("div") contains tagSelector("p")
4545
}.ASSERT {
4646
actual
4747
.xpathShouldBe("//div[./p]")
4848
}
49+
}
4950

5051
/**
5152
* Checks #1 require
5253
* @see [org.xpathqs.core.selector.extensions.containsAny]
5354
*/
5455
@Test
55-
fun r1_containsAny() =
56+
fun r1_containsAny() {
5657
WHEN {
5758
tagSelector("div") containsAny tagSelector("p")
5859
}.ASSERT {
5960
actual
6061
.xpathShouldBe("//div[.//p]")
6162
}
63+
}
6264

6365
/**
6466
* Checks #2 require
6567
* @see [org.xpathqs.core.selector.extensions.containsAny]
6668
*/
6769
@Test
68-
fun r2_containsAnyXpathWithPrefix() =
70+
fun r2_containsAnyXpathWithPrefix() {
6971
WHEN {
7072
tagSelector("div") containsAny xpathSelector("./p")
7173
}.ASSERT {
7274
actual
7375
.xpathShouldBe("//div[./p]")
7476
}
77+
}
7578

7679
/**
7780
* Checks #2 require
7881
* @see [org.xpathqs.core.selector.extensions.contains]
7982
*/
8083
@Test
81-
fun r2_containsXpathWithPrefix() =
84+
fun r2_containsXpathWithPrefix() {
8285
WHEN {
8386
tagSelector("div") contains xpathSelector("./p")
8487
}.ASSERT {
8588
actual
8689
.xpathShouldBe("//div[./p]")
8790
}
88-
91+
}
8992
/**
9093
* Checks #3 require
9194
* @see [org.xpathqs.core.selector.extensions.contains]
9295
*/
9396
@Test
94-
fun r3_containsXpathWithoutPrefix() =
97+
fun r3_containsXpathWithoutPrefix() {
9598
WHEN {
9699
tagSelector("div") contains xpathSelector("p")
97100
}.ASSERT {
98101
actual
99102
.xpathShouldBe("//div[./p]")
100103
}
101-
104+
}
102105
/**
103106
* Checks #1 require
104107
* @see [org.xpathqs.core.selector.extensions.containsParent]
105108
*/
106109
@Test
107-
fun r1_containsParent() =
110+
fun r1_containsParent() {
108111
WHEN {
109112
tagSelector("div") containsParent textSelector("some text")
110113
}.ASSERT {
111114
actual
112115
.xpathShouldBe("//div[../*[text()='some text']]")
113116
}
114-
117+
}
115118
/**
116119
* Checks #2 require
117120
* @see [org.xpathqs.core.selector.extensions.containsParent]
118121
*/
119122
@Test
120-
fun r2_containsParentXpathWithPrefix() =
123+
fun r2_containsParentXpathWithPrefix() {
121124
WHEN {
122125
tagSelector("div") containsParent xpathSelector("../p")
123126
}.ASSERT {
124127
actual
125128
.xpathShouldBe("//div[../p]")
126129
}
127-
130+
}
128131
/**
129132
* Checks #3 require
130133
* @see [org.xpathqs.core.selector.extensions.containsParent]
131134
*/
132135
@Test
133-
fun r3_containsParentXpathWithoutPrefix() =
136+
fun r3_containsParentXpathWithoutPrefix() {
134137
WHEN {
135138
tagSelector("div") containsParent xpathSelector("p")
136139
}.ASSERT {
137140
actual
138141
.xpathShouldBe("//div[../p]")
139142
}
143+
}
140144
}

src/test/kotlin/org/xpathqs/core/selector/block/BlockSelectorXpathTest.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package org.xpathqs.core.selector.block
2424

2525
import org.junit.jupiter.api.Test
2626
import org.xpathqs.core.reflection.parse
27+
import org.xpathqs.core.selector.extensions.core.clone
2728
import org.xpathqs.core.selector.extensions.core.get
2829
import org.xpathqs.core.util.SelectorFactory.tagSelector
2930
import org.xpathqs.gwt.GIVEN
@@ -72,4 +73,21 @@ class BlockSelectorXpathTest {
7273
"//div//p"
7374
}
7475
}
76+
77+
@Test
78+
fun xpathForDynamic() {
79+
GIVEN {
80+
Block(
81+
tagSelector("div")
82+
)[2].parse().clone()
83+
}.WHEN {
84+
given.toString()
85+
given.toString()
86+
given.toXpath()
87+
}.THEN {
88+
"//div[position()=2]"
89+
}.AFTER {
90+
given.toXpath()
91+
}
92+
}
7593
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) 2021 XPATH-QS
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
package org.xpathqs.core.selector.group.extensions
24+
25+
import org.junit.jupiter.api.Test
26+
import org.xpathqs.core.selector.args.SelectorArgs
27+
import org.xpathqs.core.selector.args.ValueArg
28+
import org.xpathqs.core.selector.base.BaseSelectorProps
29+
import org.xpathqs.core.selector.extensions.plus
30+
import org.xpathqs.core.selector.group.GroupSelector
31+
import org.xpathqs.core.selector.group.addGroupArg
32+
import org.xpathqs.core.util.SelectorFactory
33+
import org.xpathqs.core.util.SelectorFactory.tagSelector
34+
import org.xpathqs.gwt.GIVEN
35+
36+
class AddGroupArgTest {
37+
/**
38+
* Check #1 require
39+
* @see [org.xpathqs.core.selector.group.GroupSelector.addGroupArg]
40+
*/
41+
@Test
42+
fun r1_singleSelector() {
43+
GIVEN {
44+
GroupSelector().add(
45+
tagSelector("div")
46+
)
47+
}.WHEN {
48+
given.addGroupArg(
49+
ValueArg("position()=2")
50+
).toXpath()
51+
}.THEN {
52+
"//div[position()=2]"
53+
}
54+
}
55+
56+
/**
57+
* Check #2 require
58+
* @see [org.xpathqs.core.selector.group.GroupSelector.addGroupArg]
59+
*/
60+
@Test
61+
fun r2_multipleSelector() {
62+
GIVEN {
63+
tagSelector("div") + tagSelector("div")
64+
}.WHEN {
65+
given.addGroupArg(
66+
ValueArg("position()=2")
67+
).toXpath()
68+
}.THEN {
69+
"(//div//div)[position()=2]"
70+
}
71+
}
72+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2021 XPATH-QS
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
package org.xpathqs.core.selector.group.extensions
24+
25+
import org.junit.jupiter.api.Test
26+
import org.xpathqs.core.selector.extensions.plus
27+
import org.xpathqs.core.selector.group.prefix
28+
import org.xpathqs.core.util.SelectorFactory.tagSelector
29+
import org.xpathqs.core.util.SelectorFactory.xpathSelector
30+
import org.xpathqs.gwt.GIVEN
31+
32+
class PrefixTest {
33+
34+
/**
35+
* Check #1 require
36+
* @see org.xpathqs.core.selector.group.GroupSelector.prefix
37+
*/
38+
@Test
39+
fun r1_prefixWithSelector() {
40+
GIVEN {
41+
tagSelector("div") + tagSelector("div")
42+
}.WHEN {
43+
given.prefix("*").toXpath()
44+
}.THEN {
45+
"*div//div"
46+
}
47+
}
48+
49+
/**
50+
* Check #2 require
51+
* @see org.xpathqs.core.selector.group.GroupSelector.prefix
52+
*/
53+
@Test
54+
fun r2_prefixWithXpathSelector() {
55+
GIVEN {
56+
xpathSelector("//div") + tagSelector("div")
57+
}.WHEN {
58+
given.prefix("*").toXpath()
59+
}.THEN {
60+
"//div//div"
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)