UNPKG

fluentnode

Version:

Fluent apis for node (based on the concepts used in C#'s FluentSharp

397 lines (261 loc) 15.5 kB
<!DOCTYPE html> <html> <head> <title>Object.test.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <ul id="jump_to"> <li> <a class="large" href="javascript:void(0);">Jump To &hellip;</a> <a class="small" href="javascript:void(0);">+</a> <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="assert_Array.html"> assert_Array.litcoffee </a> <a class="source" href="assert_Boolean.html"> assert_Boolean.litcoffee </a> <a class="source" href="assert_Function.html"> assert_Function.litcoffee </a> <a class="source" href="assert_Number.html"> assert_Number.litcoffee </a> <a class="source" href="assert_Object.html"> assert_Object.litcoffee </a> <a class="source" href="assert_String.html"> assert_String.litcoffee </a> <a class="source" href="fluentnode.html"> fluentnode.coffee </a> <a class="source" href="index.html"> index.md </a> <a class="source" href="Array.html"> Array.litcoffee </a> <a class="source" href="Boolean.html"> Boolean.litcoffee </a> <a class="source" href="Function.html"> Function.litcoffee </a> <a class="source" href="Number.html"> Number.litcoffee </a> <a class="source" href="Object.html"> Object.litcoffee </a> <a class="source" href="String.html"> String.litcoffee </a> <a class="source" href="console.html"> console.litcoffee </a> <a class="source" href="crypto.html"> crypto.litcoffee </a> <a class="source" href="fs.html"> fs.litcoffee </a> <a class="source" href="http.GET.html"> http.GET.litcoffee </a> <a class="source" href="http.POST.html"> http.POST.litcoffee </a> <a class="source" href="http.Server.html"> http.Server.litcoffee </a> <a class="source" href="http.html"> http.litcoffee </a> <a class="source" href="path.html"> path.litcoffee </a> <a class="source" href="process.html"> process.litcoffee </a> <a class="source" href="encoding.html"> encoding.litcoffee </a> <a class="source" href="globals.html"> globals.litcoffee </a> <a class="source" href="assert_Array.test.html"> assert_Array.test.coffee </a> <a class="source" href="assert_Boolean.test.html"> assert_Boolean.test.coffee </a> <a class="source" href="assert_Function.test.html"> assert_Function.test.coffee </a> <a class="source" href="assert_Number.test.html"> assert_Number.test.coffee </a> <a class="source" href="assert_Object.test.html"> assert_Object.test.coffee </a> <a class="source" href="assert_String.test.html"> assert_String.test.coffee </a> <a class="source" href="fluentnode.test.html"> fluentnode.test.coffee </a> <a class="source" href="Array.test.html"> Array.test.coffee </a> <a class="source" href="Boolean.test.html"> Boolean.test.coffee </a> <a class="source" href="Function.test.html"> Function.test.coffee </a> <a class="source" href="Number.test.html"> Number.test.coffee </a> <a class="source" href="Object.test.html"> Object.test.coffee </a> <a class="source" href="String.test.html"> String.test.coffee </a> <a class="source" href="console.test.html"> console.test.coffee </a> <a class="source" href="crypto.test.html"> crypto.test.coffee </a> <a class="source" href="fs.test.html"> fs.test.coffee </a> <a class="source" href="http.GET.test.html"> http.GET.test.coffee </a> <a class="source" href="http.POST.test.html"> http.POST.test.coffee </a> <a class="source" href="http.Server.test.html"> http.Server.test.coffee </a> <a class="source" href="http.test.html"> http.test.coffee </a> <a class="source" href="path.test.html"> path.test.coffee </a> <a class="source" href="process.test.html"> process.test.coffee </a> <a class="source" href="encoding.test.html"> encoding.test.coffee </a> <a class="source" href="globals.test.html"> globals.test.coffee </a> </div> </li> </ul> <ul class="sections"> <li id="title"> <div class="annotation"> <h1>Object.test.coffee</h1> </div> </li> <li id="section-1"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-1">&#182;</a> </div> </div> <div class="content"><div class='highlight'><pre><span class="hljs-built_in">require</span>(<span class="hljs-string">'../../src/fluentnode'</span>) expect = <span class="hljs-built_in">require</span>(<span class="hljs-string">'chai'</span>).expect describe <span class="hljs-string">'| js-native | Object'</span>,<span class="hljs-function">-&gt;</span> o = {} <span class="hljs-comment"># recursive json object (should not stringify ok)</span> o.o = o it <span class="hljs-string">'str'</span>,<span class="hljs-function">-&gt;</span> <span class="hljs-string">""</span> .str().assert_Is <span class="hljs-string">""</span> <span class="hljs-string">"123"</span> .str().assert_Is <span class="hljs-string">"123"</span> [] .str().assert_Is [].toString() {} .str().assert_Is {}.toString() {<span class="hljs-attribute">a</span>:<span class="hljs-string">'1'</span>}.str().assert_Is <span class="hljs-string">"[object Object]"</span> it <span class="hljs-string">'json_Str'</span>,<span class="hljs-function">-&gt;</span> <span class="hljs-string">""</span> .json_Str().assert_Is <span class="hljs-string">"\"\""</span> <span class="hljs-string">"123"</span>.json_Str().assert_Is <span class="hljs-string">"\"123\""</span> {} .json_Str().assert_Is <span class="hljs-string">"{}"</span> {<span class="hljs-attribute">a</span>:<span class="hljs-number">1</span>}.json_Str().assert_Is <span class="hljs-string">"{\"a\":1}"</span> o .json_Str().assert_Is <span class="hljs-string">''</span> it <span class="hljs-string">'json_Pretty'</span>, <span class="hljs-function">-&gt;</span> {<span class="hljs-attribute">a</span>:<span class="hljs-number">1</span>} .json_Pretty().assert_Is <span class="hljs-string">'{\n \"a\": 1\n}'</span> [{<span class="hljs-attribute">a</span>:<span class="hljs-number">1</span>},{<span class="hljs-attribute">b</span>:<span class="hljs-number">1</span>}].json_Pretty().assert_Is <span class="hljs-string">'[\n {\n \"a\": 1\n },\n {\n \"b\": 1\n }\n]'</span> {<span class="hljs-attribute">a</span>:<span class="hljs-number">1</span>} .json_Pretty().assert_Is <span class="hljs-string">'{\n \"a\": 1\n}'</span> {<span class="hljs-attribute">null</span>:<span class="hljs-literal">null</span>} .json_Pretty().assert_Is <span class="hljs-string">'{\n "null": null\n}'</span> o .json_Pretty().assert_Is <span class="hljs-string">''</span> {}.json_pretty.assert_Is {}.json_Pretty it <span class="hljs-string">'json_inspect'</span>,<span class="hljs-function">-&gt;</span> a = <span class="hljs-literal">null</span> {<span class="hljs-attribute">null</span>:<span class="hljs-literal">null</span>}.json_Inspect().assert_Is <span class="hljs-string">'{ null: null }'</span> o .json_Inspect().assert_Is <span class="hljs-string">"{ o: [Circular] }"</span> o .json_inspect().assert_Is <span class="hljs-string">"{ o: [Circular] }"</span> it <span class="hljs-string">'keys'</span>, <span class="hljs-function">-&gt;</span> abc = { <span class="hljs-attribute">key1</span>:<span class="hljs-string">''</span>, <span class="hljs-attribute">key2</span>:<span class="hljs-string">''</span>} abc.keys().assert_Is_Equal_To([<span class="hljs-string">'key1'</span>, <span class="hljs-string">'key2'</span>]) it <span class="hljs-string">'keys_All'</span>, <span class="hljs-function">-&gt;</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">abc</span></span> <span class="hljs-attribute">constructor</span>:<span class="hljs-function">-&gt;</span> <span class="hljs-property">@key1</span> = <span class="hljs-string">''</span> <span class="hljs-property">@key2</span> = <span class="hljs-string">''</span> <span class="hljs-attribute">key1_All</span>:<span class="hljs-function">-&gt;</span> <span class="hljs-attribute">key2_All</span>:<span class="hljs-function">-&gt;</span> <span class="hljs-keyword">new</span> abc().keys() .assert_Is_Equal_To([<span class="hljs-string">'key1'</span>, <span class="hljs-string">'key2'</span>]) <span class="hljs-keyword">new</span> abc().keys_All().assert_Is_Equal_To([<span class="hljs-string">'key1'</span>, <span class="hljs-string">'key2'</span>, <span class="hljs-string">'key1_All'</span>, <span class="hljs-string">'key2_All'</span>]) it <span class="hljs-string">'values'</span>, <span class="hljs-function">-&gt;</span> abc = { <span class="hljs-attribute">key1</span>:<span class="hljs-string">'aaa'</span>, <span class="hljs-attribute">key2</span>:<span class="hljs-string">'bbb'</span>} abc.values().assert_Is_Equal_To([<span class="hljs-string">'aaa'</span>, <span class="hljs-string">'bbb'</span>]) it <span class="hljs-string">'call_Function'</span>,<span class="hljs-function"><span class="hljs-params">()</span>-&gt;</span> <span class="hljs-function"> <span class="hljs-title">check_Call_Param</span> = <span class="hljs-params">(source, param1, param2)</span>-&gt;</span> source.assert_Is_Equal_To({<span class="hljs-string">'a'</span>}) param1 .assert_Is_Equal_To(<span class="hljs-string">'b'</span>) param2 .assert_Is_Equal_To(<span class="hljs-string">'c'</span>) <span class="hljs-string">'d'</span> {<span class="hljs-string">'a'</span>}.call_Function.assert_Is_Function() {<span class="hljs-string">'a'</span>}.call_Function(check_Call_Param, <span class="hljs-string">'b'</span>, <span class="hljs-string">'c'</span>).assert_Is(<span class="hljs-string">'d'</span>) it <span class="hljs-string">'save_Json , load_Json'</span>, <span class="hljs-function">-&gt;</span> target = <span class="hljs-string">'__tmp_'</span>.add_5_Random_Letters().append_To_Process_Cwd_Path() source = { <span class="hljs-attribute">a</span>: <span class="hljs-string">'123'</span>, <span class="hljs-attribute">b</span>: <span class="hljs-string">'42'</span>} target.assert_File_Not_Exists() source.save_Json(target) target.assert_File_Exists() target.load_Json().assert_Is source <span class="hljs-string">'aaaa'</span>.save_As target target.load_Json().assert_Is {} target.file_Delete().assert_True() it <span class="hljs-string">'repl_Me'</span>,<span class="hljs-function"><span class="hljs-params">(done)</span>-&gt;</span> anObject = {a : <span class="hljs-string">'an value'</span> , b :<span class="hljs-number">2</span>} anObject.repl_Me.assert_Is_Function() replMe = anObject.repl_Me done replMe.assert_Is_Object() replMe.context.that.assert_Is(anObject) replMe.rli.close()</pre></div></div> </li> <li id="section-2"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>“”.log() # without this extra line here, coveralls fails to publish</p> </div> </li> </ul> </div> </body> </html>