<commit_before>module('lively.persistence.tests.BuildSpec').requires('lively.persistence.BuildSpec', 'lively.morphic.tests.Helper').toRun(function() {

lively.morphic.tests.MorphTests.subclass('lively.persistence.tests.BuildSpec.Morphic',
'testing', {
    test01CreateSimpleSpec: function() {
        var m = new lively.morphic.Box(lively.rect(0,0,100,100)),
            spec = m.buildSpec(),
            expected = {
                className: 'lively.morphic.Box',
                sourceModule: 'lively.morphic.Core',
                _Position: lively.pt(0,0)
            };
        this.assertMatches(expected, spec);
    },

    test02Recreate: function() {
        var m = new lively.morphic.Box(lively.rect(0,0,100,100));
        m.foo = 23;
        var spec = m.buildSpec(),
            recreated = lively.morphic.Morph.fromSpec(spec);
        this.assertEquals(lively.morphic.Box, recreated.constructor);
        this.assertEquals(23, recreated.foo);
        this.assertEquals(lively.rect(0,0,100,100), recreated.bounds());
    },
    test03RecreateWithScript: function() {
        var m = new lively.morphic.Box(lively.rect(0,0,100,100));
        m.addScript(function foo() { return 23; });
        var spec = m.buildSpec(),
            recreated = lively.morphic.Morph.fromSpec(spec);
        this.assertEquals(lively.morphic.Box, recreated.constructor);
        this.assertEquals(23, recreated.foo());
        this.assertEquals(lively.rect(0,0,100,100), recreated.bounds());
    },
    test04CreateSimpleSpecWithSubmorphs: function() {
        var m1 = new lively.morphic.Box(lively.rect(0,0,100,100)),
            m2 = new lively.morphic.Box(lively.rect(25,25,50,50));
        m1.addMorph(m2);
        var spec = m1.buildSpec(),
            expected = {
                className: 'lively.morphic.Box',
                sourceModule: 'lively.morphic.Core',
                _Position: lively.pt(0,0),
                submorphs: [{_Position: lively.pt(25,25)}]
            };
        this.assertMatches(expected, spec);
    }});

lively.morphic.tests.MorphTests.subclass('lively.persistence.tests.BuildSpec.PrintSpec',
'testing', {
    test01CreateSimpleSpec: function() {
        var m = new lively.morphic.Box(lively.rect(0,0,100,100));
        m.addScript(function foo() { return 123; });
        var spec = m.printBuildSpec(),
            expected = '{\n'
                     + '  _ClipMode: "visible",\n'
                     + '  _Extent: lively.pt(100.0,100.0),\n'
                     + '  _Position: lively.pt(0.0,0.0),\n'
                     + '  className: "lively.morphic.Box",\n'
                     + '  droppingEnabled: true,\n'
                     + '  halosEnabled: true,\n'
                     + '  sourceModule: "lively.morphic.Core",\n'
                     + '  submorphs: [],\n'
                     + '  foo: function foo() { return 123; }\n'
                     + '}'
        this.assertEquals(expected, spec);
    }

});

<commit_msg>towards buildSpec for attributeConnections<commit_after>module('lively.persistence.tests.BuildSpec').requires('lively.persistence.BuildSpec', 'lively.morphic.tests.Helper').toRun(function() {

lively.morphic.tests.MorphTests.subclass('lively.persistence.tests.BuildSpec.Morphic',
'testing', {
    test01CreateSimpleSpec: function() {
        var m = new lively.morphic.Box(lively.rect(0,0,100,100)),
            spec = m.buildSpec(),
            expected = {
                className: 'lively.morphic.Box',
                sourceModule: 'lively.morphic.Core',
                _Position: lively.pt(0,0)
            };
        this.assertMatches(expected, spec);
    },

    test02Recreate: function() {
        var m = new lively.morphic.Box(lively.rect(0,0,100,100));
        m.foo = 23;
        var spec = m.buildSpec(),
            recreated = lively.morphic.Morph.fromSpec(spec);
        this.assertEquals(lively.morphic.Box, recreated.constructor);
        this.assertEquals(23, recreated.foo);
        this.assertEquals(lively.rect(0,0,100,100), recreated.bounds());
    },
    test03RecreateWithScript: function() {
        var m = new lively.morphic.Box(lively.rect(0,0,100,100));
        m.addScript(function foo() { return 23; });
        var spec = m.buildSpec(),
            recreated = lively.morphic.Morph.fromSpec(spec);
        this.assertEquals(lively.morphic.Box, recreated.constructor);
        this.assertEquals(23, recreated.foo());
        this.assertEquals(lively.rect(0,0,100,100), recreated.bounds());
    },
    test04CreateSimpleSpecWithSubmorphs: function() {
        var m1 = new lively.morphic.Box(lively.rect(0,0,100,100)),
            m2 = new lively.morphic.Box(lively.rect(25,25,50,50));
        m1.addMorph(m2);
        var spec = m1.buildSpec(),
            expected = {
                className: 'lively.morphic.Box',
                sourceModule: 'lively.morphic.Core',
                _Position: lively.pt(0,0),
                submorphs: [{_Position: lively.pt(25,25)}]
            };
        this.assertMatches(expected, spec);
    },
    test05BuildSpecWithConnection: function() {
        var m = new lively.morphic.Box(lively.rect(0,0,100,100));
        lively.bindings.connect(m, 'foo', m, 'bar');
        m.foo = 3;
        var spec = m.buildSpec(),
            expected = {
                className: 'lively.morphic.Box',
                foo: 3,
                sourceModule: 'lively.morphic.Core',
                _Position: lively.pt(0,0)
            };
        this.assertMatches(expected, spec);
        this.assert(!spec.$$foo, 'connection meta attribute was serialized');
    }
});

lively.morphic.tests.MorphTests.subclass('lively.persistence.tests.BuildSpec.PrintSpec',
'testing', {
    test01CreateSimpleSpec: function() {
        var m = new lively.morphic.Box(lively.rect(0,0,100,100));
        m.addScript(function foo() { return 123; });
        var spec = m.printBuildSpec(),
            expected = '{\n'
                     + '  _ClipMode: "visible",\n'
                     + '  _Extent: lively.pt(100.0,100.0),\n'
                     + '  _Position: lively.pt(0.0,0.0),\n'
                     + '  className: "lively.morphic.Box",\n'
                     + '  droppingEnabled: true,\n'
                     + '  halosEnabled: true,\n'
                     + '  sourceModule: "lively.morphic.Core",\n'
                     + '  submorphs: [],\n'
                     + '  foo: function foo() { return 123; }\n'
                     + '}'
        this.assertEquals(expected, spec);
    }

});


{'fraction_non_alphanumeric': 0.14858454475899005, 'fraction_numerical': 0.036725325172149964, 'mean_word_length': 2.0830188679245283, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3213705', 'n_tokens_mistral': 2243, 'n_tokens_neox': 2023, 'n_words': 289}