Skip to content

Commit

Permalink
Merge pull request #7 from 4TechTeams/feature/domain-extension
Browse files Browse the repository at this point in the history
Feature/domain extension
  • Loading branch information
frne authored Nov 14, 2024
2 parents 407dea4 + 5ec4f7a commit cb522d8
Show file tree
Hide file tree
Showing 13 changed files with 848 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This file was automatically generated from Domain.kt by Knit tool. Do not edit.
package com.fotechteams.valuetypes.examples.exampleNetworkApexDomain01

import com.fortechteams.valuetypes.network.ApexDomain
import io.kotest.matchers.shouldBe

fun test() {
val apex = ApexDomain("example", "com")
apex.name shouldBe "example"
apex.tld shouldBe "com"
apex.toString() shouldBe "example.com"
apex.toFQDN() shouldBe "example.com."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This file was automatically generated from Domain.kt by Knit tool. Do not edit.
package com.fotechteams.valuetypes.examples.exampleNetworkApexDomain02

import com.fortechteams.valuetypes.network.ApexDomain
import com.fortechteams.valuetypes.network.TopLevelDomain
import io.kotest.matchers.shouldBe

fun test() {
val apex = ApexDomain("example", "com")
val parent = apex.parent()
parent shouldBe TopLevelDomain("com")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This file was automatically generated from Domain.kt by Knit tool. Do not edit.
package com.fotechteams.valuetypes.examples.exampleNetworkDomain01

import com.fortechteams.valuetypes.network.Domain
import com.fortechteams.valuetypes.network.Subdomain
import io.kotest.matchers.shouldBe

fun test() {
// Parse different types of domains
val tld = Domain.parse("com")
val apex = Domain.parse("example.com")
val subdomain = Domain.parse("www.example.com")

// Convert to FQDN (Fully Qualified Domain Name)
tld.toFQDN() shouldBe "com."
apex.toFQDN() shouldBe "example.com."
subdomain.toFQDN() shouldBe "www.example.com."

// Access domain parts
(subdomain as Subdomain).apexDomain.toString() shouldBe "example.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This file was automatically generated from Domain.kt by Knit tool. Do not edit.
package com.fotechteams.valuetypes.examples.exampleNetworkDomain02

import com.fortechteams.valuetypes.network.Domain
import io.kotest.matchers.shouldBe

fun test() {
Domain.parse("www.example.com").toFQDN() shouldBe "www.example.com."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This file was automatically generated from Domain.kt by Knit tool. Do not edit.
package com.fotechteams.valuetypes.examples.exampleNetworkDomain03

import com.fortechteams.valuetypes.network.Domain
import com.fortechteams.valuetypes.network.TopLevelDomain
import com.fortechteams.valuetypes.network.ApexDomain
import com.fortechteams.valuetypes.network.Subdomain
import io.kotest.matchers.shouldBe

fun test() {
Domain.parse("com") shouldBe TopLevelDomain("com")
Domain.parse("example.com") shouldBe ApexDomain("example", "com")
Domain.parse("www.example.com") shouldBe
Subdomain(listOf("www"), "example", "com")

// Invalid domains throw InvalidDomainException
runCatching { Domain.parse("invalid..com") }.isFailure shouldBe true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This file was automatically generated from Domain.kt by Knit tool. Do not edit.
package com.fotechteams.valuetypes.examples.exampleNetworkSubdomain01

import com.fortechteams.valuetypes.network.Subdomain
import io.kotest.matchers.shouldBe

fun test() {
val sub = Subdomain(listOf("www"), "example", "com")

// Access individual parts
sub.subdomainLabels shouldBe listOf("www")
sub.apexName shouldBe "example"
sub.tld shouldBe "com"

// Get the apex domain
sub.apexDomain.toString() shouldBe "example.com"

// Get full hierarchy
val complex = Subdomain(listOf("dev", "staging"), "example", "com")
complex.getSubdomainHierarchy().map { it.toString() } shouldBe listOf(
"dev.staging.example.com",
"staging.example.com"
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This file was automatically generated from Domain.kt by Knit tool. Do not edit.
package com.fotechteams.valuetypes.examples.exampleNetworkSubdomain02

import com.fortechteams.valuetypes.network.Subdomain
import com.fortechteams.valuetypes.network.ApexDomain
import io.kotest.matchers.shouldBe

fun test() {
// Single level subdomain
val www = Subdomain(listOf("www"), "example", "com")
www.parent() shouldBe ApexDomain("example", "com")

// Multi-level subdomain
val dev = Subdomain(listOf("dev", "www"), "example", "com")
dev.parent().toString() shouldBe "www.example.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This file was automatically generated from Domain.kt by Knit tool. Do not edit.
package com.fotechteams.valuetypes.examples.exampleNetworkSubdomain03

import com.fortechteams.valuetypes.network.Subdomain
import io.kotest.matchers.shouldBe

fun test() {
val domain = Subdomain(
labels = listOf("dev", "staging"),
apexName = "example",
tld = "com"
)

val hierarchy = domain.getSubdomainHierarchy()
hierarchy.map { it.toString() } shouldBe listOf(
"dev.staging.example.com",
"staging.example.com"
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This file was automatically generated from Domain.kt by Knit tool. Do not edit.
package com.fotechteams.valuetypes.examples.exampleNetworkTopLevelDomain01

import com.fortechteams.valuetypes.network.TopLevelDomain
import io.kotest.matchers.shouldBe

fun test() {
val tld = TopLevelDomain("com")
tld.toString() shouldBe "com"
tld.toFQDN() shouldBe "com."
tld.labels shouldBe listOf("com")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// This file was automatically generated from Domain.kt by Knit tool. Do not edit.
package com.fortechteams.valuetypes.examples.test

import kotlin.test.Test
import kotlinx.coroutines.test.runTest

class NetworkDomainKnitTest {
@Test fun exampleNetworkDomain01() = runTest {
com.fotechteams.valuetypes.examples.exampleNetworkDomain01.test()
}

@Test fun exampleNetworkDomain02() = runTest {
com.fotechteams.valuetypes.examples.exampleNetworkDomain02.test()
}

@Test fun exampleNetworkDomain03() = runTest {
com.fotechteams.valuetypes.examples.exampleNetworkDomain03.test()
}

@Test fun exampleNetworkTopLevelDomain01() = runTest {
com.fotechteams.valuetypes.examples.exampleNetworkTopLevelDomain01.test()
}

@Test fun exampleNetworkApexDomain01() = runTest {
com.fotechteams.valuetypes.examples.exampleNetworkApexDomain01.test()
}

@Test fun exampleNetworkApexDomain02() = runTest {
com.fotechteams.valuetypes.examples.exampleNetworkApexDomain02.test()
}

@Test fun exampleNetworkSubdomain01() = runTest {
com.fotechteams.valuetypes.examples.exampleNetworkSubdomain01.test()
}

@Test fun exampleNetworkSubdomain02() = runTest {
com.fotechteams.valuetypes.examples.exampleNetworkSubdomain02.test()
}

@Test fun exampleNetworkSubdomain03() = runTest {
com.fotechteams.valuetypes.examples.exampleNetworkSubdomain03.test()
}

}
Loading

0 comments on commit cb522d8

Please sign in to comment.