Skip to content

Commit

Permalink
Fix Address#postcode for 'nl' locale
Browse files Browse the repository at this point in the history
  • Loading branch information
serpro69 committed May 9, 2022
1 parent e79b8f2 commit 8a1abbb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and the project versioning adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)

## [1.11.0] - UNRELEASED
###
### Added
- [#122](https://github.com/serpro69/kotlin-faker/pull/122) [core] Add (unique) `numerify`, `letterify`, `bothify` and `regexify` functions through `StringProvider`

### Fixed
- [#125](https://github.com/serpro69/kotlin-faker/issues/125) [core] Generating postcode with locale "nl" gives back expression rather than result

## [1.10.0] - 2022-02-20
### Added
- [#115](https://github.com/serpro69/kotlin-faker/pull/115) [core] Add Crossfit® provider to Faker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.serpro69.kfaker.provider
import io.github.serpro69.kfaker.faker
import io.kotest.assertions.throwables.shouldNotThrow
import io.kotest.core.spec.style.DescribeSpec
import io.kotest.matchers.string.shouldMatch

class AddressIT : DescribeSpec({
describe("Address Provider") {
Expand All @@ -25,5 +26,11 @@ class AddressIT : DescribeSpec({
shouldNotThrow<NoSuchElementException> { address("lv").city() }
}
}

context("nl locale") {
it("should generate a valid postcode") {
address("nl").postcode() shouldMatch Regex("""[1-9]\d{3} \w{2}""")
}
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ class Address internal constructor(fakerService: FakerService) : AbstractFakeDat
fun buildingNumber() = with(fakerService) { resolve("building_number").numerify() }
fun community() = resolve("community")
fun secondaryAddress() = with(fakerService) { resolve("secondary_address").numerify() }
fun postcode() = with(fakerService) { resolve("postcode").numerify() }
fun postcode() = with(fakerService) {
when (faker.config.locale) {
"nl" -> resolve("postcode").generexify().replace("/", "")
else -> resolve("postcode").numerify()
}
}

fun postcodeByState(state: String) = with(fakerService) { resolve("postcode_by_state", state).numerify() }
fun state() = resolve("state")
fun stateAbbr() = resolve("state_abbr")
Expand All @@ -46,3 +52,4 @@ class Address internal constructor(fakerService: FakerService) : AbstractFakeDat
// fix #87
internal fun cityRoot() = resolve("city_root")
}

0 comments on commit 8a1abbb

Please sign in to comment.