Fix fork() for projects that use Kiss as a haxelib
This commit is contained in:
1
cloner/.gitignore
vendored
1
cloner/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
bin/test/
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
language: objective-c
|
|
||||||
|
|
||||||
install:
|
|
||||||
- brew install neko haxe
|
|
||||||
- cd ..
|
|
||||||
- mkdir haxelib
|
|
||||||
- haxelib setup haxelib
|
|
||||||
- haxelib install hxcpp > /dev/null
|
|
||||||
- haxelib install hx3compat > /dev/null
|
|
||||||
before_script:
|
|
||||||
- cd $TRAVIS_BUILD_DIR
|
|
||||||
script:
|
|
||||||
- sh test.sh -e
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
version: "{build}"
|
|
||||||
|
|
||||||
clone_folder: C:\projects\cloner
|
|
||||||
|
|
||||||
environment:
|
|
||||||
global:
|
|
||||||
HAXELIB_ROOT: C:\projects\haxelib
|
|
||||||
|
|
||||||
install:
|
|
||||||
# Install haxe and neko
|
|
||||||
- cinst neko --version 2.2.0 -y
|
|
||||||
- cinst haxe -y
|
|
||||||
- RefreshEnv
|
|
||||||
- neko -version
|
|
||||||
- haxe -version
|
|
||||||
# Setup haxelib
|
|
||||||
- mkdir "%HAXELIB_ROOT%"
|
|
||||||
- haxelib setup "%HAXELIB_ROOT%"
|
|
||||||
- haxelib install record-macros
|
|
||||||
- haxelib install hxcpp
|
|
||||||
|
|
||||||
build_script:
|
|
||||||
- cd test
|
|
||||||
- haxe compile.hxml
|
|
||||||
- cd ..
|
|
||||||
|
|
||||||
test_script:
|
|
||||||
- echo CPP
|
|
||||||
- bin\test\TestMain-debug.exe
|
|
||||||
- echo NEKO
|
|
||||||
- neko bin\test\TestMain.n
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "cloner",
|
|
||||||
"url" : "https://github.com/thomasuster/cloner",
|
|
||||||
"license": "MIT",
|
|
||||||
"tags": ["clone", "copy", "deep"],
|
|
||||||
"description": "A deep copy algorithm for haxe",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"classPath": "src/",
|
|
||||||
"releasenote": "",
|
|
||||||
"contributors": ["thomasuster"],
|
|
||||||
"dependencies": {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
set -e
|
|
||||||
cd test
|
|
||||||
haxe compile.hxml
|
|
||||||
cd ..
|
|
||||||
echo CPP
|
|
||||||
bin/test/TestMain-debug
|
|
||||||
echo NEKO
|
|
||||||
neko bin/test/TestMain.n
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
import classes.ClassTypeProperty;
|
|
||||||
import classes.ABCEnum;
|
|
||||||
import cloner.Cloner;
|
|
||||||
import classes.ArrayProperty;
|
|
||||||
import classes.ClassProperty;
|
|
||||||
import classes.BoolProperty;
|
|
||||||
import classes.NullClass;
|
|
||||||
class TestCloner extends haxe.unit.TestCase {
|
|
||||||
|
|
||||||
var cloner:Cloner;
|
|
||||||
|
|
||||||
override public function setup() {
|
|
||||||
cloner = new Cloner();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testclone() {
|
|
||||||
var value:NullClass = new NullClass();
|
|
||||||
assertTrue(cloner.clone(value) != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testBoolProperty() {
|
|
||||||
var value:BoolProperty = new BoolProperty(true);
|
|
||||||
assertTrue(cloner.clone(value).property);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testArrayProperty() {
|
|
||||||
var value:ArrayProperty = new ArrayProperty([true]);
|
|
||||||
assertTrue(cloner.clone(value).property[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testStringMap():Void {
|
|
||||||
var value:Map<String, Int> = new Map<String, Int>();
|
|
||||||
value.set('you',1);
|
|
||||||
assertTrue(cloner.clone(value).get('you') == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIntMap():Void {
|
|
||||||
var value:Map<Int, Int> = new Map<Int, Int>();
|
|
||||||
value.set(1,2);
|
|
||||||
assertTrue(cloner.clone(value).get(1) == 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testObjectsInMap():Void {
|
|
||||||
var value:Map<Int, NullClass> = new Map<Int, NullClass>();
|
|
||||||
var v:NullClass = new NullClass();
|
|
||||||
value.set(1,v);
|
|
||||||
assertTrue(cloner.clone(value).get(1) != v);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testString():Void {
|
|
||||||
assertTrue(cloner.clone('a') == 'a');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testClassType():Void {
|
|
||||||
assertTrue(cloner.clone(NullClass) == NullClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testEnum():Void {
|
|
||||||
assertTrue(cloner.clone(ABCEnum.b) == ABCEnum.b);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testClassProperty():Void {
|
|
||||||
var value:ClassProperty = new ClassProperty();
|
|
||||||
var inValue = new BoolProperty(true);
|
|
||||||
value.property = inValue;
|
|
||||||
var outValue:BoolProperty = cloner.clone(value).property;
|
|
||||||
assertTrue(outValue.property);
|
|
||||||
assertFalse(inValue == outValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAnonObjectAreDifferentCopies():Void {
|
|
||||||
var value = { a: 10, b: 20 };
|
|
||||||
var clone = cloner.clone(value);
|
|
||||||
Reflect.setField(value, 'a', 33);
|
|
||||||
assertEquals(10, Reflect.getProperty(clone, 'a'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testEmbededAnonObject():Void {
|
|
||||||
var inner = {b: 5};
|
|
||||||
var value = { a: 10, inner: inner };
|
|
||||||
var clone = cloner.clone(value);
|
|
||||||
Reflect.setField(inner, 'b', 33);
|
|
||||||
|
|
||||||
var cloneInner = Reflect.getProperty(clone, 'inner');
|
|
||||||
assertEquals(5, Reflect.getProperty(cloneInner, 'b'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testClassRefInsideAnObj():Void {
|
|
||||||
var value:ClassTypeProperty = new ClassTypeProperty();
|
|
||||||
value.property = BoolProperty;
|
|
||||||
var outValue:ClassTypeProperty = cloner.clone(value);
|
|
||||||
assertEquals(outValue.property, BoolProperty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
import cloner.Cloner;
|
|
||||||
import classes.ClassProperty;
|
|
||||||
import classes.BoolProperty;
|
|
||||||
class TestClonerCache extends haxe.unit.TestCase {
|
|
||||||
|
|
||||||
var cloner:Cloner;
|
|
||||||
var input:Array<ClassProperty>;
|
|
||||||
var outcome:Array<ClassProperty>;
|
|
||||||
|
|
||||||
override public function setup() {
|
|
||||||
cloner = new Cloner();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testReferences():Void {
|
|
||||||
setupOutcomeWithReferences();
|
|
||||||
assertTrue(outcome[0].property == outcome[1].property);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testNoSideEffects():Void {
|
|
||||||
setupOutcomeWithReferences();
|
|
||||||
outcome[0].property = true;
|
|
||||||
outcome = cloner.clone(input);
|
|
||||||
assertFalse(outcome[0].property);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setupOutcomeWithReferences():Void {
|
|
||||||
var a:ClassProperty = new ClassProperty();
|
|
||||||
var b:ClassProperty = new ClassProperty();
|
|
||||||
var c:BoolProperty = new BoolProperty();
|
|
||||||
a.property = c;
|
|
||||||
b.property = c;
|
|
||||||
input = [a, b];
|
|
||||||
outcome = cloner.clone(input);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import haxe.unit.TestRunner;
|
|
||||||
class TestMain {
|
|
||||||
|
|
||||||
static function main() {
|
|
||||||
var runner:TestRunner = new TestRunner();
|
|
||||||
runner.add(new TestCloner());
|
|
||||||
runner.add(new TestClonerCache());
|
|
||||||
runner.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package classes;
|
|
||||||
enum ABCEnum {
|
|
||||||
a;
|
|
||||||
b;
|
|
||||||
c;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package classes;
|
|
||||||
class ArrayProperty {
|
|
||||||
public var property:Array<Bool>;
|
|
||||||
public function new(v:Array<Bool>):Void {
|
|
||||||
property = v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package classes;
|
|
||||||
class BoolProperty {
|
|
||||||
public var property:Bool;
|
|
||||||
public function new(v:Bool=false):Void {
|
|
||||||
property = v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package classes;
|
|
||||||
class ClassProperty {
|
|
||||||
public var property:Dynamic;
|
|
||||||
public function new():Void {}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package classes;
|
|
||||||
class ClassTypeProperty {
|
|
||||||
public var property:Class<Dynamic>;
|
|
||||||
public function new():Void {}
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
package classes;
|
|
||||||
class NullClass {
|
|
||||||
public function new():Void {}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
-cp .
|
|
||||||
-cp ../src
|
|
||||||
-lib hx3compat
|
|
||||||
-main TestMain
|
|
||||||
-debug
|
|
||||||
-cpp ../bin/test
|
|
||||||
|
|
||||||
--next
|
|
||||||
|
|
||||||
-cp .
|
|
||||||
-cp ../src
|
|
||||||
-lib hx3compat
|
|
||||||
-main TestMain
|
|
||||||
-debug
|
|
||||||
-neko ../bin/test/TestMain.n
|
|
||||||
@@ -7,7 +7,7 @@ import haxe.macro.PositionTools;
|
|||||||
import sys.io.File;
|
import sys.io.File;
|
||||||
#end
|
#end
|
||||||
import kiss.Kiss;
|
import kiss.Kiss;
|
||||||
import cloner.Cloner;
|
import kiss.cloner.Cloner;
|
||||||
|
|
||||||
typedef Command = () -> Void;
|
typedef Command = () -> Void;
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ class EmbeddedScript {
|
|||||||
for (command in commands) {
|
for (command in commands) {
|
||||||
// a fork needs to be a thorough copy that includes all of the EmbeddedScript subclass's
|
// a fork needs to be a thorough copy that includes all of the EmbeddedScript subclass's
|
||||||
// fields, otherwise DSL state will be lost when forking, which is unacceptable
|
// fields, otherwise DSL state will be lost when forking, which is unacceptable
|
||||||
var fork = new cloner.Cloner().clone(this);
|
var fork = new kiss.cloner.Cloner().clone(this);
|
||||||
fork.instructions[instructionPointer] = command;
|
fork.instructions[instructionPointer] = command;
|
||||||
fork.run();
|
fork.run();
|
||||||
fork;
|
fork;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package cloner;
|
package kiss.cloner;
|
||||||
import Array;
|
import Array;
|
||||||
import haxe.ds.ObjectMap;
|
import haxe.ds.ObjectMap;
|
||||||
import Type.ValueType;
|
import Type.ValueType;
|
||||||
@@ -102,7 +102,12 @@ class Cloner {
|
|||||||
for (i in 0...fields.length) {
|
for (i in 0...fields.length) {
|
||||||
var field = fields[i];
|
var field = fields[i];
|
||||||
var property = Reflect.getProperty(inValue, field);
|
var property = Reflect.getProperty(inValue, field);
|
||||||
|
try {
|
||||||
Reflect.setField(outValue, field, _clone(property));
|
Reflect.setField(outValue, field, _clone(property));
|
||||||
|
} catch (s) {
|
||||||
|
// There will be errors on C++ when trying to assign to a member function.
|
||||||
|
// They're not important, because the function will already be on the clone.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return outValue;
|
return outValue;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package cloner;
|
package kiss.cloner;
|
||||||
import haxe.Constraints.IMap;
|
import haxe.Constraints.IMap;
|
||||||
import cloner.Cloner;
|
import kiss.cloner.Cloner;
|
||||||
import Type.ValueType;
|
import Type.ValueType;
|
||||||
class MapCloner<K>{
|
class MapCloner<K>{
|
||||||
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
haxelib dev kiss ../../kiss
|
|
||||||
haxe build.hxml
|
haxe build.hxml
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
haxelib dev kiss ../../kiss
|
|
||||||
echo "" > test-output.txt
|
echo "" > test-output.txt
|
||||||
expected=$'hey\nhey\nhey'
|
expected=$'hey\nhey\nhey'
|
||||||
if [[ $(uname) == *"MINGW"* ]] || [ $TRAVIS_OS_NAME = "windows" ]; then
|
if [[ $(uname) == *"MINGW"* ]] || [ $TRAVIS_OS_NAME = "windows" ]; then
|
||||||
|
|||||||
@@ -9,5 +9,4 @@ if [ ! -z "$TRAVIS_OS_NAME" ]; then
|
|||||||
npm install pdf-lib
|
npm install pdf-lib
|
||||||
haxelib install hxnodejs
|
haxelib install hxnodejs
|
||||||
fi
|
fi
|
||||||
haxelib dev kiss ../../kiss
|
|
||||||
haxe build.hxml
|
haxe build.hxml
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
haxelib dev kiss ../../
|
|
||||||
haxe build.hxml
|
haxe build.hxml
|
||||||
@@ -9,6 +9,7 @@ fi
|
|||||||
for PROJECT_DIR in $PROJECT_DIRS
|
for PROJECT_DIR in $PROJECT_DIRS
|
||||||
do
|
do
|
||||||
if [ ! -z "${TRAVIS_OS_NAME}" ]; then
|
if [ ! -z "${TRAVIS_OS_NAME}" ]; then
|
||||||
|
haxelib dev kiss kiss
|
||||||
(cd $PROJECT_DIR && haxelib install all)
|
(cd $PROJECT_DIR && haxelib install all)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user