diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index fed7224..514ba39 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -105,6 +105,7 @@ jobs: - name: "build kotlin" run: | cd kotlin && echo "build kotlin" + gradle build gradle test ruby: @@ -147,4 +148,5 @@ jobs: - name: "build swift" run: | cd swift && echo "build swift" - swift --version + swift build + swift test diff --git a/kotlin/build.gradle b/kotlin/build.gradle deleted file mode 100644 index 5338570..0000000 --- a/kotlin/build.gradle +++ /dev/null @@ -1,74 +0,0 @@ -group = "com.adviser.ipaddress" -version = "0.2.5" - -buildscript { - ext.kotlin_version = '1.2.41' - repositories { - mavenCentral() - } - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - -apply plugin: "idea" -apply plugin: "java" -apply plugin: "kotlin" -/* -apply plugin: "application" -apply plugin: "org.junit.platform.gradle.plugin" - -junitPlatform { - filters { - engines { - include 'spek' - } - } -} -mainClassName = "app.MainKt" -*/ - -jar { - manifest { - attributes 'Implementation-Title': 'ipaddress kotlin', - 'Implementation-Version': version - } -} - - -// defaultsTasks 'run' - - -repositories { - mavenCentral() - jcenter() -} - -dependencies { -} - -sourceSets.test.java.srcDirs += 'src/test' - sourceSets { - main.kotlin.srcDirs += './src/main' - } - -repositories { - mavenCentral() -} - -dependencies { - compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version" - testCompile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" - testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" - testCompile 'junit:junit:4.11' - // testCompile 'org.junit.platform:junit-platform-runner:1.0.0-M4' - // testRuntime 'org.jetbrains.spek:spek-junit-platform-engine:1.1.2' -} - -test.testClassesDir = project.tasks.compileTestKotlin.destinationDir - -task wrapper(type: Wrapper) { - gradleVersion="4.1" -} - diff --git a/kotlin/gradle/wrapper/gradle-wrapper.jar b/kotlin/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e708b1c Binary files /dev/null and b/kotlin/gradle/wrapper/gradle-wrapper.jar differ diff --git a/kotlin/gradle/wrapper/gradle-wrapper.properties b/kotlin/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..be52383 --- /dev/null +++ b/kotlin/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/kotlin/gradlew b/kotlin/gradlew new file mode 100755 index 0000000..4f906e0 --- /dev/null +++ b/kotlin/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/kotlin/gradlew.bat b/kotlin/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/kotlin/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/kotlin/lib/build.gradle.kts b/kotlin/lib/build.gradle.kts new file mode 100644 index 0000000..3cd2ccb --- /dev/null +++ b/kotlin/lib/build.gradle.kts @@ -0,0 +1,40 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * This generated file contains a sample Kotlin library project to get you started. + * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle + * User Manual available at https://docs.gradle.org/6.7/userguide/building_java_projects.html + */ + +plugins { + // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin. + id("org.jetbrains.kotlin.jvm") version "1.3.72" + + // Apply the java-library plugin for API and implementation separation. + `java-library` +} + +repositories { + // Use JCenter for resolving dependencies. + jcenter() +} + +dependencies { + // Align versions of all Kotlin components + implementation(platform("org.jetbrains.kotlin:kotlin-bom")) + + // Use the Kotlin JDK 8 standard library. + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + + // This dependency is used internally, and not exposed to consumers on their own compile classpath. + implementation("com.google.guava:guava:29.0-jre") + + // Use the Kotlin test library. + testImplementation("org.jetbrains.kotlin:kotlin-test") + + // Use the Kotlin JUnit integration. + testImplementation("org.jetbrains.kotlin:kotlin-test-junit") + + // This dependency is exported to consumers, that is to say found on their compile classpath. + api("org.apache.commons:commons-math3:3.6.1") +} diff --git a/kotlin/src/main/com/adviser/ipaddress/kotlin/IPAddress.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/IPAddress.kt similarity index 100% rename from kotlin/src/main/com/adviser/ipaddress/kotlin/IPAddress.kt rename to kotlin/lib/src/main/kotlin/com/adviser/ipaddress/IPAddress.kt diff --git a/kotlin/src/main/com/adviser/ipaddress/kotlin/IpBits.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/IpBits.kt similarity index 100% rename from kotlin/src/main/com/adviser/ipaddress/kotlin/IpBits.kt rename to kotlin/lib/src/main/kotlin/com/adviser/ipaddress/IpBits.kt diff --git a/kotlin/src/main/com/adviser/ipaddress/kotlin/IpV4.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/IpV4.kt similarity index 100% rename from kotlin/src/main/com/adviser/ipaddress/kotlin/IpV4.kt rename to kotlin/lib/src/main/kotlin/com/adviser/ipaddress/IpV4.kt diff --git a/kotlin/src/main/com/adviser/ipaddress/kotlin/IpV6.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/IpV6.kt similarity index 100% rename from kotlin/src/main/com/adviser/ipaddress/kotlin/IpV6.kt rename to kotlin/lib/src/main/kotlin/com/adviser/ipaddress/IpV6.kt diff --git a/kotlin/src/main/com/adviser/ipaddress/kotlin/IpVersion.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/IpVersion.kt similarity index 100% rename from kotlin/src/main/com/adviser/ipaddress/kotlin/IpVersion.kt rename to kotlin/lib/src/main/kotlin/com/adviser/ipaddress/IpVersion.kt diff --git a/kotlin/src/main/com/adviser/ipaddress/kotlin/Ipv6Loopback.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Ipv6Loopback.kt similarity index 100% rename from kotlin/src/main/com/adviser/ipaddress/kotlin/Ipv6Loopback.kt rename to kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Ipv6Loopback.kt diff --git a/kotlin/src/main/com/adviser/ipaddress/kotlin/Ipv6Mapped.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Ipv6Mapped.kt similarity index 100% rename from kotlin/src/main/com/adviser/ipaddress/kotlin/Ipv6Mapped.kt rename to kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Ipv6Mapped.kt diff --git a/kotlin/src/main/com/adviser/ipaddress/kotlin/Ipv6Unspec.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Ipv6Unspec.kt similarity index 100% rename from kotlin/src/main/com/adviser/ipaddress/kotlin/Ipv6Unspec.kt rename to kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Ipv6Unspec.kt diff --git a/kotlin/src/main/com/adviser/ipaddress/kotlin/Prefix.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Prefix.kt similarity index 100% rename from kotlin/src/main/com/adviser/ipaddress/kotlin/Prefix.kt rename to kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Prefix.kt diff --git a/kotlin/src/main/com/adviser/ipaddress/kotlin/Prefix128.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Prefix128.kt similarity index 100% rename from kotlin/src/main/com/adviser/ipaddress/kotlin/Prefix128.kt rename to kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Prefix128.kt diff --git a/kotlin/src/main/com/adviser/ipaddress/kotlin/Prefix32.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Prefix32.kt similarity index 100% rename from kotlin/src/main/com/adviser/ipaddress/kotlin/Prefix32.kt rename to kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Prefix32.kt diff --git a/kotlin/src/main/com/adviser/ipaddress/kotlin/Result.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Result.kt similarity index 100% rename from kotlin/src/main/com/adviser/ipaddress/kotlin/Result.kt rename to kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Result.kt diff --git a/kotlin/src/main/com/adviser/ipaddress/kotlin/Rle.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Rle.kt similarity index 100% rename from kotlin/src/main/com/adviser/ipaddress/kotlin/Rle.kt rename to kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Rle.kt diff --git a/kotlin/src/test/com/adviser/ipaddress/kotlin/TestIpAddress.kt b/kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestIpAddress.kt similarity index 98% rename from kotlin/src/test/com/adviser/ipaddress/kotlin/TestIpAddress.kt rename to kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestIpAddress.kt index b114b44..59a8284 100644 --- a/kotlin/src/test/com/adviser/ipaddress/kotlin/TestIpAddress.kt +++ b/kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestIpAddress.kt @@ -1,6 +1,8 @@ package com.adviser.ipaddress.kotlin -import org.junit.Test +import kotlin.test.Test +import kotlin.test.assertTrue + import kotlin.test.assertEquals import kotlin.test.assertTrue @@ -50,6 +52,7 @@ class TestIpAddress { @Test fun test_method_ipaddress() { + // assertTrue(false, "someLibraryMethod should return 'true'") assertTrue(IPAddress.parse(setup().valid_ipv4).isOk()) assertTrue(IPAddress.parse(setup().valid_ipv6).isOk()) assertTrue(IPAddress.parse(setup().valid_mapped).isOk()) diff --git a/kotlin/src/test/com/adviser/ipaddress/kotlin/TestIpv4.kt b/kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestIpv4.kt similarity index 99% rename from kotlin/src/test/com/adviser/ipaddress/kotlin/TestIpv4.kt rename to kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestIpv4.kt index 68dab84..f24ad1d 100644 --- a/kotlin/src/test/com/adviser/ipaddress/kotlin/TestIpv4.kt +++ b/kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestIpv4.kt @@ -1,6 +1,7 @@ package com.adviser.ipaddress.kotlin -import org.junit.Test +import kotlin.test.Test + import java.math.BigInteger import kotlin.test.assertEquals import kotlin.test.assertTrue diff --git a/kotlin/src/test/com/adviser/ipaddress/kotlin/TestIpv6.kt b/kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestIpv6.kt similarity index 99% rename from kotlin/src/test/com/adviser/ipaddress/kotlin/TestIpv6.kt rename to kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestIpv6.kt index 43252bd..79527cd 100644 --- a/kotlin/src/test/com/adviser/ipaddress/kotlin/TestIpv6.kt +++ b/kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestIpv6.kt @@ -1,7 +1,6 @@ package com.adviser.ipaddress.kotlin -import org.junit.Assert.assertArrayEquals -import org.junit.Test +import kotlin.test.Test import java.math.BigInteger import kotlin.test.assertEquals diff --git a/kotlin/src/test/com/adviser/ipaddress/kotlin/TestIpv6Loopback.kt b/kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestIpv6Loopback.kt similarity index 100% rename from kotlin/src/test/com/adviser/ipaddress/kotlin/TestIpv6Loopback.kt rename to kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestIpv6Loopback.kt diff --git a/kotlin/src/test/com/adviser/ipaddress/kotlin/TestIpv6Mapped.kt b/kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestIpv6Mapped.kt similarity index 99% rename from kotlin/src/test/com/adviser/ipaddress/kotlin/TestIpv6Mapped.kt rename to kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestIpv6Mapped.kt index 3028eaa..37241e1 100644 --- a/kotlin/src/test/com/adviser/ipaddress/kotlin/TestIpv6Mapped.kt +++ b/kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestIpv6Mapped.kt @@ -1,6 +1,6 @@ package com.adviser.ipaddress.kotlin -import org.junit.Test +import kotlin.test.Test import java.math.BigInteger import kotlin.test.assertEquals import kotlin.test.assertTrue diff --git a/kotlin/src/test/com/adviser/ipaddress/kotlin/TestIpv6Unspec.kt b/kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestIpv6Unspec.kt similarity index 97% rename from kotlin/src/test/com/adviser/ipaddress/kotlin/TestIpv6Unspec.kt rename to kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestIpv6Unspec.kt index 48c03ab..3cf3fcd 100644 --- a/kotlin/src/test/com/adviser/ipaddress/kotlin/TestIpv6Unspec.kt +++ b/kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestIpv6Unspec.kt @@ -1,7 +1,6 @@ package com.adviser.ipaddress.kotlin - -import org.junit.Test +import kotlin.test.Test import java.math.BigInteger import kotlin.test.assertEquals diff --git a/kotlin/src/test/com/adviser/ipaddress/kotlin/TestPrefix128.kt b/kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestPrefix128.kt similarity index 100% rename from kotlin/src/test/com/adviser/ipaddress/kotlin/TestPrefix128.kt rename to kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestPrefix128.kt diff --git a/kotlin/src/test/com/adviser/ipaddress/kotlin/TestPrefix32.kt b/kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestPrefix32.kt similarity index 98% rename from kotlin/src/test/com/adviser/ipaddress/kotlin/TestPrefix32.kt rename to kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestPrefix32.kt index 1439583..9bb78c1 100644 --- a/kotlin/src/test/com/adviser/ipaddress/kotlin/TestPrefix32.kt +++ b/kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestPrefix32.kt @@ -1,8 +1,7 @@ package com.adviser.ipaddress.kotlin -import org.junit.Assert.assertArrayEquals -import org.junit.Test +import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertTrue diff --git a/kotlin/src/test/com/adviser/ipaddress/kotlin/TestRle.kt b/kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestRle.kt similarity index 99% rename from kotlin/src/test/com/adviser/ipaddress/kotlin/TestRle.kt rename to kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestRle.kt index 111b2f7..b40c5be 100644 --- a/kotlin/src/test/com/adviser/ipaddress/kotlin/TestRle.kt +++ b/kotlin/lib/src/test/kotlin/com/adviser/ipaddress/TestRle.kt @@ -1,7 +1,6 @@ package com.adviser.ipaddress.kotlin -import org.junit.Test - +import kotlin.test.Test class TestRle { diff --git a/kotlin/settings.gradle.kts b/kotlin/settings.gradle.kts new file mode 100644 index 0000000..a0f42a7 --- /dev/null +++ b/kotlin/settings.gradle.kts @@ -0,0 +1,11 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * The settings file is used to specify which projects to include in your build. + * + * Detailed information about configuring a multi-project build in Gradle can be found + * in the user manual at https://docs.gradle.org/6.7/userguide/multi_project_builds.html + */ + +rootProject.name = "com.adviser.ipaddress" +include("lib") diff --git a/swift/Package.resolved b/swift/Package.resolved new file mode 100644 index 0000000..eeae82b --- /dev/null +++ b/swift/Package.resolved @@ -0,0 +1,16 @@ +{ + "object": { + "pins": [ + { + "package": "BigInt", + "repositoryURL": "https://github.com/attaswift/BigInt.git", + "state": { + "branch": null, + "revision": "889a1ecacd73ccc189c5cb29288048f186c44ed9", + "version": "5.2.1" + } + } + ] + }, + "version": 1 +} diff --git a/swift/Package.swift b/swift/Package.swift index 14d1cdb..069eca6 100644 --- a/swift/Package.swift +++ b/swift/Package.swift @@ -1,9 +1,17 @@ +// swift-tools-version:5.3 import PackageDescription let package = Package( name: "IpAddress", - targets: [], dependencies: [ - .Package(url: "https://github.com/lorentey/BigInt.git", majorVersion: 2, minor: 2) + .package(url: "https://github.com/attaswift/BigInt.git", from: "5.2.1") + ], + targets: [ + .target( + name: "IpAddress", + dependencies: ["BigInt"]), + .testTarget( + name: "IpAddressTests", + dependencies: ["BigInt", "IpAddress"]) ] ) diff --git a/swift/Sources/IpBits.swift b/swift/Sources/IpAddress/IpBits.swift similarity index 98% rename from swift/Sources/IpBits.swift rename to swift/Sources/IpAddress/IpBits.swift index 93dbe31..5041753 100644 --- a/swift/Sources/IpBits.swift +++ b/swift/Sources/IpAddress/IpBits.swift @@ -157,7 +157,7 @@ public class IpBits { for part in ip_bits.parts(host_address) { ret += sep; let tmp = String((0x10000 + part), radix: 16); - ret += String(tmp.characters.dropFirst(1)) + ret += String(tmp.dropFirst(1)) sep = ":"; } return ret; diff --git a/swift/Sources/IpVersion.swift b/swift/Sources/IpAddress/IpVersion.swift similarity index 100% rename from swift/Sources/IpVersion.swift rename to swift/Sources/IpAddress/IpVersion.swift diff --git a/swift/Sources/ipaddress.swift b/swift/Sources/IpAddress/ipaddress.swift similarity index 99% rename from swift/Sources/ipaddress.swift rename to swift/Sources/IpAddress/ipaddress.swift index 8ad6be0..bccaef3 100644 --- a/swift/Sources/ipaddress.swift +++ b/swift/Sources/IpAddress/ipaddress.swift @@ -9,9 +9,10 @@ typealias ToIpv4 = (_ source: IPAddress) -> IPAddress; public typealias EachFn = (_ source: IPAddress) -> Void; extension String { - public func index(of char: Character) -> Int? { - if let idx = characters.index(of: char) { - return characters.distance(from: startIndex, to: idx) + public func index(of char: Character) -> String.Index? { + if let idx = self.firstIndex(of: char) { + // return self.distance(from: startIndex, to: idx) + return idx; } return nil } @@ -452,7 +453,7 @@ public class IPAddress : Equatable, CustomStringConvertible { var ret = [String](); let leading = 1 << UInt(self.ip_bits.part_bits); for i in self.parts() { - ret.append(String(String(leading + UInt(i), radix: 16).characters.dropFirst(1))); + ret.append(String(String(leading + Int(i), radix: 16).dropFirst(1))); } return ret; } @@ -856,7 +857,7 @@ public class IPAddress : Equatable, CustomStringConvertible { public func bits() -> String { let num = String(self.host_address, radix: 2); var ret = ""; - for _ in num.characters.count...Int(self.ip_bits.bits-1) { + for _ in num.count...Int(self.ip_bits.bits-1) { ret += "0"; } ret += num; @@ -1225,7 +1226,7 @@ public class IPAddress : Equatable, CustomStringConvertible { return dup; } public func split(_ subnets: UInt) -> [IPAddress]? { - if (subnets == 0 || (1 << UInt(self.prefix.host_prefix())) <= subnets) { + if (subnets == 0 || BigUInt(1 << self.prefix.host_prefix()) <= subnets) { return nil; } let networks = self.subnet(self.newprefix(UInt8(subnets))!.num); diff --git a/swift/Sources/ipv4.swift b/swift/Sources/IpAddress/ipv4.swift similarity index 98% rename from swift/Sources/ipv4.swift rename to swift/Sources/IpAddress/ipv4.swift index d0f310c..ace23f6 100644 --- a/swift/Sources/ipv4.swift +++ b/swift/Sources/IpAddress/ipv4.swift @@ -69,7 +69,7 @@ public class Ipv4 { IPAddress.parse("169.254.0.0/16")!, IPAddress.parse("172.16.0.0/12")!, IPAddress.parse("192.168.0.0/16")!] - .index(where: { $0.includes(my) }) != nil + .firstIndex(where: { $0.includes(my) }) != nil } public class func ipv4_is_loopback(_ my: IPAddress) -> Bool { diff --git a/swift/Sources/ipv6.swift b/swift/Sources/IpAddress/ipv6.swift similarity index 100% rename from swift/Sources/ipv6.swift rename to swift/Sources/IpAddress/ipv6.swift diff --git a/swift/Sources/ipv6_loopback.swift b/swift/Sources/IpAddress/ipv6_loopback.swift similarity index 100% rename from swift/Sources/ipv6_loopback.swift rename to swift/Sources/IpAddress/ipv6_loopback.swift diff --git a/swift/Sources/ipv6_mapped.swift b/swift/Sources/IpAddress/ipv6_mapped.swift similarity index 100% rename from swift/Sources/ipv6_mapped.swift rename to swift/Sources/IpAddress/ipv6_mapped.swift diff --git a/swift/Sources/ipv6_unspec.swift b/swift/Sources/IpAddress/ipv6_unspec.swift similarity index 100% rename from swift/Sources/ipv6_unspec.swift rename to swift/Sources/IpAddress/ipv6_unspec.swift diff --git a/swift/Sources/prefix.swift b/swift/Sources/IpAddress/prefix.swift similarity index 100% rename from swift/Sources/prefix.swift rename to swift/Sources/IpAddress/prefix.swift diff --git a/swift/Sources/prefix128.swift b/swift/Sources/IpAddress/prefix128.swift similarity index 100% rename from swift/Sources/prefix128.swift rename to swift/Sources/IpAddress/prefix128.swift diff --git a/swift/Sources/prefix32.swift b/swift/Sources/IpAddress/prefix32.swift similarity index 100% rename from swift/Sources/prefix32.swift rename to swift/Sources/IpAddress/prefix32.swift diff --git a/swift/Sources/rle.swift b/swift/Sources/IpAddress/rle.swift similarity index 100% rename from swift/Sources/rle.swift rename to swift/Sources/IpAddress/rle.swift diff --git a/swift/Tests/IpAddressTests/Ipv4Tests.swift b/swift/Tests/IpAddressTests/Ipv4Tests.swift index 974228b..4f0a23f 100644 --- a/swift/Tests/IpAddressTests/Ipv4Tests.swift +++ b/swift/Tests/IpAddressTests/Ipv4Tests.swift @@ -71,11 +71,11 @@ class Ipv4Tests : XCTestCase { ipv4t.netmask_values["192.168.0.0/24"] = "255.255.255.0" ipv4t.netmask_values["192.168.100.4/30"] = "255.255.255.252" - ipv4t.decimal_values["0.0.0.0/0"] = BigUInt("0")! - ipv4t.decimal_values["10.0.0.0/8"] = BigUInt("167772160")! - ipv4t.decimal_values["172.16.0.0/16"] = BigUInt("2886729728")! - ipv4t.decimal_values["192.168.0.0/24"] = BigUInt("3232235520")! - ipv4t.decimal_values["192.168.100.4/30"] = BigUInt("3232261124")! + ipv4t.decimal_values["0.0.0.0/0"] = BigUInt("0") + ipv4t.decimal_values["10.0.0.0/8"] = BigUInt("167772160") + ipv4t.decimal_values["172.16.0.0/16"] = BigUInt("2886729728") + ipv4t.decimal_values["192.168.0.0/24"] = BigUInt("3232235520") + ipv4t.decimal_values["192.168.100.4/30"] = BigUInt("3232261124") ipv4t.broadcast["10.0.0.0/8"] = "10.255.255.255/8" diff --git a/swift/Tests/IpAddressTests/Ipv6MappedTests.swift b/swift/Tests/IpAddressTests/Ipv6MappedTests.swift index e8b540d..3496295 100644 --- a/swift/Tests/IpAddressTests/Ipv6MappedTests.swift +++ b/swift/Tests/IpAddressTests/Ipv6MappedTests.swift @@ -32,15 +32,15 @@ class Ipv6MappedTests: XCTestCase { s: "::ffff:172.16.10.1", sstr: "::ffff:172.16.10.1/32", string: "0000:0000:0000:0000:0000:ffff:ac10:0a01/128", - u128: BigUInt("281473568475649")!, + u128: BigUInt("281473568475649"), address: "::ffff:ac10:a01/128" ); - ipv6.valid_mapped["::13.1.68.3"] = BigUInt("281470899930115")!; - ipv6.valid_mapped["0:0:0:0:0:ffff:129.144.52.38"] = BigUInt("281472855454758")!; - ipv6.valid_mapped["::ffff:129.144.52.38"] = BigUInt("281472855454758")!; - ipv6.valid_mapped_ipv6["::ffff:13.1.68.3"] = BigUInt("281470899930115")!; - ipv6.valid_mapped_ipv6["0:0:0:0:0:ffff:8190:3426"] = BigUInt("281472855454758")!; - ipv6.valid_mapped_ipv6["::ffff:8190:3426"] = BigUInt("281472855454758")!; + ipv6.valid_mapped["::13.1.68.3"] = BigUInt("281470899930115"); + ipv6.valid_mapped["0:0:0:0:0:ffff:129.144.52.38"] = BigUInt("281472855454758"); + ipv6.valid_mapped["::ffff:129.144.52.38"] = BigUInt("281472855454758"); + ipv6.valid_mapped_ipv6["::ffff:13.1.68.3"] = BigUInt("281470899930115"); + ipv6.valid_mapped_ipv6["0:0:0:0:0:ffff:8190:3426"] = BigUInt("281472855454758"); + ipv6.valid_mapped_ipv6["::ffff:8190:3426"] = BigUInt("281472855454758"); ipv6.valid_mapped_ipv6_conversion["::ffff:13.1.68.3"] = "13.1.68.3"; ipv6.valid_mapped_ipv6_conversion["0:0:0:0:0:ffff:8190:3426"] = "129.144.52.38"; ipv6.valid_mapped_ipv6_conversion["::ffff:8190:3426"] = "129.144.52.38"; diff --git a/swift/Tests/IpAddressTests/Ipv6Tests.swift b/swift/Tests/IpAddressTests/Ipv6Tests.swift index a6fe1c3..0f6d886 100644 --- a/swift/Tests/IpAddressTests/Ipv6Tests.swift +++ b/swift/Tests/IpAddressTests/Ipv6Tests.swift @@ -109,10 +109,10 @@ class Ipv6Tests : XCTestCase { XCTAssertEqual(false, setup().ip.is_network()); } func test_method_network_u128() { - XCTAssertNotNil(Ipv6.from_int(BigUInt("42540766411282592856903984951653826560")!, 64)!.eq(setup().ip.network())); + XCTAssertNotNil(Ipv6.from_int(BigUInt("42540766411282592856903984951653826560"), 64)!.eq(setup().ip.network())); } func test_method_broadcast_u128() { - XCTAssertNotNil(Ipv6.from_int(BigUInt("42540766411282592875350729025363378175")!, 64)!.eq(setup().ip.broadcast())); + XCTAssertNotNil(Ipv6.from_int(BigUInt("42540766411282592875350729025363378175"), 64)!.eq(setup().ip.broadcast())); } func test_method_size() { var ip = IPAddress.parse("2001:db8::8:800:200c:417a/64")!; diff --git a/swift/Tests/IpAddressTests/Prefix32Tests.swift b/swift/Tests/IpAddressTests/Prefix32Tests.swift index 55e00a5..364ba48 100644 --- a/swift/Tests/IpAddressTests/Prefix32Tests.swift +++ b/swift/Tests/IpAddressTests/Prefix32Tests.swift @@ -36,10 +36,10 @@ func setup() -> Prefix32Test { p32t.octets_hash[24] = [255, 255, 255, 0]; p32t.octets_hash[30] = [255, 255, 255, 252]; p32t.u32_hash[0] = BigUInt(0); - p32t.u32_hash[8] = BigUInt("4278190080")!; - p32t.u32_hash[16] = BigUInt("4294901760")!; - p32t.u32_hash[24] = BigUInt("4294967040")!; - p32t.u32_hash[30] = BigUInt("4294967292")!; + p32t.u32_hash[8] = BigUInt("4278190080"); + p32t.u32_hash[16] = BigUInt("4294901760"); + p32t.u32_hash[24] = BigUInt("4294967040"); + p32t.u32_hash[30] = BigUInt("4294967292"); return p32t; }