<commit_before>/*jshint white: false, strict: false, plusplus: false, onevar: false,
  nomen: false */
/*global module: false, gladius: false, stop: false, start: false,
  expect: false, asyncTest: false, ok: false, deepEqual: false, equal: false */

(function() {
    var engine = null;


    module('base/Resource', {

        setup : function() {
            stop();

            gladius.create({
                debug : true
            }, function(instance) {
                engine = instance;
                start();
            });
        },
        teardown : function() {
            engine = null;
        }
    });

    // Some day we can do even better by using mocks and ensuring that any HTTP
    // status code < 200 or > 299 fails.
    asyncTest( 'ensure onfailure gets called on loading non-existent file',
                function () {
                  
        expect(1);             
    
        var options = {
            url : "no-such-url-exists",

            onsuccess : function itemOnSuccess(item) {
                ok( false, "non-existent file load shouldn't call onsuccess" );
                start();
            },

            onfailure : function itemOnFailure(error) {
                ok( true, "non-existent file load should call onfailure");

                // TD should check format of error once we decide it

                start();                
            }
        };

        // it was WAY too painful to figure out the syntax
        // to trigger the intended semantics here; having two partial
        // constructors that take different options is confusing.
        // this object model needs simplifying.
        var resource = new engine.base.Resource()(options);
     });
     
     // TD: test data URLs, and commutativity/normalization of params:
     //
     // "data:gladius/script;core.script.test?x=1&y=2"
     // "data:gladius/script;core.script.test?y=2&x=1"
  
     // TD: test that result not populated before oncomplete is called and 
     // result returned on async completion
     
     // TD test loading of a resource when passing a constructor for the
     // for processing the returned JSON:
     //
     // var resource = new engine.base.Resource(someConstructor)(options)
}());<commit_msg>Added test of API to load a typed resource<commit_after>/*jshint white: false, strict: false, plusplus: false, onevar: false,
  nomen: false */
/*global module: false, gladius: false, stop: false, start: false, test: false,
  expect: false, asyncTest: false, ok: false, deepEqual: false, equal: false */

(function() {
    var engine = null;


    module('base/Resource', {

        setup : function() {
            stop();

            gladius.create({
                debug : true
            }, function(instance) {
                engine = instance;
                start();
            });
        },
        teardown : function() {
            engine = null;
        }
    });

    asyncTest( 'construct a new resource type and an instance of it', 
           function() {
             expect(1);
             

             var Text = engine.base.Resource({
               type: 'Text',
               construct: function constructText( data ) {
                 this.value = data;
               }
             });
               
             Text({
               url: "data:text/plain,Hello%20World",
               onsuccess: function onTextSuccess( text ) {
                 deepEqual( text ,
                    { value: "Hello World" },
                    "text object constructed from data URL");
                 start();
               },
               onfailure: function onTextFailure( error ) {
                 ok(false, "onTextFailure improperly called with " + error);
                 start();
               }
             });
           });
    
    // Some day we can do even better by using mocks and ensuring that any HTTP
    // status code < 200 or > 299 fails.
    asyncTest( 'ensure onfailure gets called on loading non-existent file',
                function () {
                  
        expect(1);             
    
        var options = {
            url : "no-such-url-exists",

            onsuccess : function itemOnSuccess(item) {
                ok( false, "non-existent file load shouldn't call onsuccess" );
                start();
            },

            onfailure : function itemOnFailure(error) {
                ok( true, "non-existent file load should call onfailure");

                // TD should check format of error once we decide it

                start();                
            }
        };

        // it was WAY too painful to figure out the syntax
        // to trigger the intended semantics here; having two partial
        // constructors that take different options is confusing.
        // this object model needs simplifying.
        var resource = new engine.base.Resource()(options);
     });

}());

     
     // TD: test data URLs, and commutativity/normalization of params:
     //
     // "data:gladius/script;core.script.test?x=1&y=2"
     // "data:gladius/script;core.script.test?y=2&x=1"
  
{'fraction_non_alphanumeric': 0.10139588987979838, 'fraction_numerical': 0.004846839860411012, 'mean_word_length': 1.5252080274106705, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1319574', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1264, 'n_words': 429}