All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rhino1.7.6.testsrc.tests.e4x.Expressions.11.6.2.js Maven / Gradle / Ivy

Go to download

Rhino is an open-source implementation of JavaScript written entirely in Java. It is typically embedded into Java applications to provide scripting to end users.

There is a newer version: 1.7.15
Show newest version
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

gTestfile = '11.6.2.js';

START("11.6.2 - XMLList Assignment");

// Set the name of the only customer in the order to Fred Jones
order =

    
        John Smith
    
    
        Big Screen Television
        1299.99
    
    
        DVD Player
        399.99
    
;
   
correct =

    
        Fred Jones
    
    
        Big Screen Television
        1299.99
    
    
        DVD Player
        399.99
    
;

order.customer.name = "Fred Jones";
TEST(1, correct, order);

// Replace all the hobbies for the only customer in the order
order =

    
        John Smith
        Biking
    
    
        Big Screen Television
        1299.99
    
    
        DVD Player
        399.99
    
;

correct =

    
        John Smith
        shopping
    
    
        Big Screen Television
        1299.99
    
    
        DVD Player
        399.99
    
;

order.customer.hobby = "shopping"
TEST(2, correct, order);

// Attempt to set the sale date of the item.  Throw an exception if more than 1 item exists.
order =

    
        John Smith
    
    
        Big Screen Television
        1299.99
        01-05-2002
    
;

correct =

    
        John Smith
    
    
        Big Screen Television
        1299.99
        05-07-2002
    
;

order.item.saledate = "05-07-2002"
TEST(3, correct, order);

order =

    
        John Smith
        Biking
    
    
        Big Screen Television
        1299.99
    
    
        DVD Player
        399.99
    
;

try {
    order.item.saledate = "05-07-2002";
    SHOULD_THROW(4);
} catch (ex) {
    TEST(4, "TypeError", ex.name);
}

// Replace all the employee's hobbies with their new favorite pastime
emps =

    
        John
        20
        skiing
    
    
        Sue
        30
        running
    
    
        Ted
        35
        Biking
    
;

correct =

    
        John
        20
        skiing
    
    
        Sue
        30
        running
    
    
        Ted
        35
        working
    
;

emps.employee.(@id == 3).hobby = "working";
TEST(5, correct, emps);

// Replace the first employee with George
emps =

    
        John
        20
    
    
        Sue
        30
    
    
        Ted
        35
    
;

correct =

    
        George
        27
    
    
        Sue
        30
    
    
        Ted
        35
    
;

emps.employee[0] = George27;
TEST(6, emps, correct);

// Add a new employee to the end of the employee list
emps =

    
        John
        20
    
    
        Sue
        30
    
    
        Ted
        35
    
;

correct =

    
        John
        20
    
    
        Sue
        30
    
    
        Ted
        35
    
    
        Frank
        39
    
;

emps.employee += Frank39;
TEST(7, correct, emps);

// Add a new employee to the end of the employee list
emps =

    
        John
        20
    
    
        Sue
        30
    
    
        Ted
        35
    
;

correct =

    
        John
        20
    
    
        Sue
        30
    
    
        Ted
        35
    
    
        Frank
        39
    
;

emps.employee[emps.employee.length()] = Frank39;
TEST(7, correct, emps);

END();




© 2015 - 2024 Weber Informatics LLC | Privacy Policy