Skip to content

Commit fafa1a6

Browse files
authored
Issue48 (#49)
* Closes #48
1 parent 9b30f49 commit fafa1a6

File tree

10 files changed

+54
-6
lines changed

10 files changed

+54
-6
lines changed

.github/badges/branches.svg

Lines changed: 1 addition & 1 deletion
Loading

.github/badges/jacoco.svg

Lines changed: 1 addition & 1 deletion
Loading

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2424

25-
version = "0.0.2"
25+
version = "0.0.3"
2626

2727
plugins {
2828
kotlin("jvm") version "1.5.0"

out/test/resources/config/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
constants:
22
text_arg: "@text_test"
3+
upperCase: "true"
4+
id_arg: "@resource-id"
35

46
timeouts:
57
default: 100

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ Apache Maven
1717
<dependency>
1818
<groupId>org.xpathqs</groupId>
1919
<artifactId>xpathqs-core</artifactId>
20-
<version>0.0.1</version>
20+
<version>0.0.3</version>
2121
</dependency>
2222
```
2323

2424
Gradle Kotlin DSL
2525
```kotlin
26-
implementation("org.xpathqs:xpathqs-core:0.0.1")
26+
implementation("org.xpathqs:xpathqs-core:0.0.3")
2727
```
2828

2929
Gradle Groovy DSL
3030
```groovy
31-
implementation 'org.xpathqs:xpathqs-core:0.0.1'
31+
implementation 'org.xpathqs:xpathqs-core:0.0.3'
3232
```
3333

3434
## Quick Example

src/main/kotlin/org/xpathqs/core/constants/Global.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ open class CoreGlobalProps(
7070
*/
7171
val ID_ARG: String
7272
get() = props["constants.id_arg"] as? String ?: "@id"
73+
74+
/**
75+
* Converts tags in [org.xpathqs.core.selector.selector.Selector.toXpath] to upper case
76+
* Upper case for tag is a requirement for such HTML parsers like `NekoHtml`
77+
*/
78+
val UPPER_CASE_FOR_TAG: Boolean
79+
get() = (props["constants.upperCase"] as? String)?.toBoolean() ?: false
7380
}
7481

7582
/**

src/main/kotlin/org/xpathqs/core/selector/selector/SelectorProps.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
package org.xpathqs.core.selector.selector
2424

25+
import org.xpathqs.core.constants.Global
2526
import org.xpathqs.core.selector.args.SelectorArgs
2627
import org.xpathqs.core.selector.base.BaseSelectorProps
2728

@@ -40,6 +41,7 @@ open class SelectorProps(
4041
* Get Xpath string based on [prefix] + [tag] + [args]
4142
*/
4243
override fun toXpath(): String {
44+
val tag = if (Global.UPPER_CASE_FOR_TAG) this.tag.uppercase() else this.tag
4345
return "$prefix$tag${args.toXpath()}"
4446
}
4547

src/test/kotlin/org/xpathqs/core/util/PropertyFacadeTest.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,27 @@ package org.xpathqs.core.util
2424

2525
import assertk.assertThat
2626
import assertk.assertions.isEqualTo
27+
import org.junit.jupiter.api.AfterEach
2728
import org.junit.jupiter.api.Test
2829

2930
import org.xpathqs.core.constants.CoreGlobalProps
31+
import org.xpathqs.core.constants.Global
32+
import org.xpathqs.core.selector.extensions.id
33+
import org.xpathqs.core.selector.extensions.text
34+
import org.xpathqs.core.util.SelectorFactory.tagSelector
35+
import org.xpathqs.xpathShouldBe
3036

3137
internal class PropertyFacadeTest {
3238

3339
val PATH = "config/config.yml"
3440

41+
@AfterEach
42+
fun restoreDefaults() {
43+
Global.update(
44+
CoreGlobalProps("config/configDefault.yml")
45+
)
46+
}
47+
3548
@Test
3649
fun parseWithInputStream() {
3750
assertThat(
@@ -54,4 +67,19 @@ internal class PropertyFacadeTest {
5467
).isEqualTo("@text_test")
5568
}
5669

70+
@Test
71+
fun tagSelectorDefault() {
72+
tagSelector("div").text("hello").id("someId")
73+
.xpathShouldBe("//div[text()='hello' and @id='someId']")
74+
}
75+
76+
@Test
77+
fun tagSelectorOverridden() {
78+
Global.update(
79+
CoreGlobalProps("config/config.yml")
80+
)
81+
tagSelector("div").text("hello").id("someId")
82+
.xpathShouldBe("//DIV[@text_test='hello' and @resource-id='someId']")
83+
}
84+
5785
}

src/test/resources/config/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
constants:
22
text_arg: "@text_test"
3+
upperCase: "true"
4+
id_arg: "@resource-id"
35

46
timeouts:
57
default: 100
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
constants:
2+
text_arg: "text()"
3+
upperCase: "false"
4+
id_arg: "@id"
5+
6+
timeouts:
7+
default: 100

0 commit comments

Comments
 (0)