require('../src/Object')
require('../src/console')
expect     = require('chai').expect


describe 'Object',->


    it 'str',->
        expect(""    .str).to.be.an('Function')
        expect(""    .str()).to.equal(""   .toString() )
        expect("123" .str()).to.equal("123".toString() )
        expect([]    .str()).to.equal([]   .toString() )
        expect({}    .str()).to.equal({}   .toString() )
        expect({a:'1'}.str()).to.equal("[object Object]")

    it 'json_Str',->
        expect(""   .json_Str).to.be.an('Function')
        expect(""   .json_Str()).to.equal("\"\"")
        expect("123".json_Str()).to.equal("\"123\"")
        expect({}   .json_Str()).to.equal("{}")
        expect({a:1}.json_Str()).to.equal("{\"a\":1}")

    it 'json_Pretty', ->
        expect({a:1}        .json_Pretty()).to.equal('{\n  \"a\": 1\n}')
        expect([{a:1},{b:1}].json_Pretty()).to.equal('[\n  {\n    \"a\": 1\n  },\n  {\n    \"b\": 1\n  }\n]')

        expect({a:1}        .json_pretty()).to.equal('{\n  \"a\": 1\n}')

    it 'json_inspect',->
        expect("".json_Inspect).to.be.an('Function')
        o = {}
        o.o = o
        expect(o.json_Inspect()).to.equal("{ o: [Circular] }")
        expect(o.json_inspect()).to.equal("{ o: [Circular] }")

    it 'keys', ->
        abc = { key1:'', key2:''}
        abc.keys().assert_Is_Equal_To(['key1', 'key2'])

    it 'keys_All', ->
        class abc
            constructor:->
                @key1 = ''
                @key2 = ''
            key1_All:->
            key2_All:->

        new abc().keys()    .assert_Is_Equal_To(['key1', 'key2'])
        new abc().keys_All().assert_Is_Equal_To(['key1', 'key2', 'key1_All', 'key2_All'])

    it 'values', ->
        abc = { key1:'aaa', key2:'bbb'}
        abc.values().assert_Is_Equal_To(['aaa', 'bbb'])

    it 'call_Function',()->
        check_Call_Param = (source, param1, param2)->
            source.assert_Is_Equal_To({'a'})
            param1 .assert_Is_Equal_To('b')
            param2 .assert_Is_Equal_To('c')
            'd'
        {'a'}.call_Function.assert_Is_Function()
        {'a'}.call_Function(check_Call_Param, 'b', 'c').assert_Is('d')

    it 'save_Json , load_Json', ->
        target = '__tmp_'.add_5_Random_Letters().append_To_Process_Cwd_Path()
        source = { a: '123', b: '42'}
        target.assert_File_Not_Exists()
        source.save_Json(target)
        target.assert_File_Exists()
        target.load_Json().assert_Is(source)
        target.file_Delete().assert_True()

    it 'repl_Me',(done)->
        anObject = {a : 'an value' , b :2}
        anObject.repl_Me.assert_Is_Function()

        replMe = anObject.repl_Me done
        replMe.assert_Is_Object()
        replMe.context.that.assert_Is(anObject)
        replMe.rli.close()
        "".log()                    # without this extra line here, coveralls fails to publish
