示例#1
0
(function test_operators_round_trip() {
    var operators;
    var hash;
    var narrow;

    operators = [
        {operator: 'stream', operand: 'devel'},
        {operator: 'topic', operand: 'algol'},
    ];
    hash = hashchange.operators_to_hash(operators);
    assert.equal(hash, '#narrow/stream/devel/topic/algol');

    narrow = hashchange.parse_narrow(hash.split('/'));
    assert.deepEqual(narrow, [
        {operator: 'stream', operand: 'devel', negated: false},
        {operator: 'topic', operand: 'algol', negated: false},
    ]);

    operators = [
        {operator: 'stream', operand: 'devel'},
        {operator: 'topic', operand: 'visual c++', negated: true},
    ];
    hash = hashchange.operators_to_hash(operators);
    assert.equal(hash, '#narrow/stream/devel/-topic/visual.20c.2B.2B');

    narrow = hashchange.parse_narrow(hash.split('/'));
    assert.deepEqual(narrow, [
        {operator: 'stream', operand: 'devel', negated: false},
        {operator: 'topic', operand: 'visual c++', negated: true},
    ]);

}());
示例#2
0
(function test_people_slugs() {
    var operators;
    var hash;
    var narrow;

    var alice = {
        email: '*****@*****.**',
        user_id: 42,
        full_name: 'Alice Smith',
    };

    people.add(alice);
    operators = [
        {operator: 'sender', operand: '*****@*****.**'},
    ];
    hash = hashchange.operators_to_hash(operators);
    assert.equal(hash, '#narrow/sender/42-alice');
    narrow = hashchange.parse_narrow(hash.split('/'));
    assert.deepEqual(narrow, [
        {operator: 'sender', operand: '*****@*****.**', negated: false},
    ]);

    operators = [
        {operator: 'pm-with', operand: '*****@*****.**'},
    ];
    hash = hashchange.operators_to_hash(operators);
    assert.equal(hash, '#narrow/pm-with/42-alice');
}());