Example #1
0
/// A special split-merge operation
/// Which means the second change was placed OVER the previous one on both side
/// (A) 1:0:BC
/// (B) 0:0:AD
/// (M) 0:0:ABCD
void TextChangeTest::testMerge6_splitMerge()
{
    TextChange a(1,0,"bc");
    TextChange* b = new TextChange(0,0,"ad");
    testTrue( a.giveAndMerge(0,b) );
    testEqual( a.offset(), 0 );
    testEqual( a.docLength(), 0 );
    testEqual( a.storedText(), "abcd" );
}
Example #2
0
/// MERGE 1
/// - a[bc]defgh  =(x)=> axdefgh   (A) 1:1:bc
/// - a[xd]efgh   =(y)=> ayefgh    (B) 1:1:xd
/// = This should be merge into:   (M) 1:1:bcd        =>  bc + d
void TextChangeTest::testMerge1()
{
    TextChange a(1,1,"bc");
    TextChange* b = new TextChange(1,1,"xd");

    testTrue( a.giveAndMerge(0,b) );
    testEqual( a.offset(), 1 );
    testEqual( a.docLength(), 1 );
    testEqual( a.storedText(), "bcd" );
}
Example #3
0
/// MERGE 5
/// - a[b]cdefgh     =(wxyz)=> awxyzcdefgh   (A) 1:4:b
/// - awx[y]zcdefgh  =(q)=>    awxqzcdefgh   (B) 3:1:y
/// = This should be merge into:             (M) 1:4:b     =>  b
void TextChangeTest::testMerge5()
{
    TextChange a(1,4,"b");
    TextChange* b = new TextChange(3,1,"y");

    testTrue( a.giveAndMerge(0,b) );
    testEqual( a.offset(), 1 );
    testEqual( a.docLength(), 4 );
    testEqual( a.storedText(), "b" );
}
Example #4
0
/// MERGE 2
/// - a[bc]defgh   =(xyz)=> axyzdefgh (A) 1:3:bc
/// - [axyz]defgh  =(q)=>   qdefgh    (B) 0:1:axyz
/// = This should be merge into:      (M) 0:1:abc     =>  a + bc
void TextChangeTest::testMerge2()
{
    TextChange a(1,3,"bc");
    TextChange* b = new TextChange(0,1,"axyz");

    testTrue( a.giveAndMerge(0,b) );
    testEqual( a.offset(), 0 );
    testEqual( a.docLength(), 1 );
    testEqual( a.storedText(), "abc" );
}
Example #5
0
File: mips.c Project: gybjm2016/Lab
int getoffset(Operand operand){
	int i =0;
	while(i<lastOffsetIndex){
		if(testEqual(operand,offsetArray[i].name)==1)
			return offsetArray[i].offset;
		i++;
	}
	return -1;
}
Example #6
0
void testReplacement(const string& input,
                     const string& expected,
                     InstrCode initial,
                     InstrCode replacement,
                     InstrCode next1 = InstrCodeCount,
                     InstrCode next2 = InstrCodeCount)
{
    Stack<Value> result;
    Stack<Env*> globals;
    bool ok = CompileModule(input, globals, result);
    testTrue(ok);
    Stack<Block*> block(result.as<CodeObject>()->block());

    InstrThunk* instrp = block->findInstr(Instr_Lambda);
    assert(instrp);
    Instr* instr = instrp->data;
    assert(instr->code() == Instr_Lambda);
    LambdaInstr* lambda = static_cast<LambdaInstr*>(instr);
    instrp = lambda->block()->findInstr(initial);
    assert(instrp);

    ok = interp->exec(block, result);
    if (!ok)
        cerr << "Error: " << result.asObject()->as<Exception>()->message() << endl;
    testTrue(ok);
    testEqual(repr(result.get()), expected);

    instr = instrp->data;
    testEqual(instrName(instr->code()), instrName(replacement));

    if (next1 < InstrCodeCount) {
        instr = getNextInstr(instr);
        assert(instr);
        testEqual(instrName(instr->code()), instrName(next1));

        if (next2 < InstrCodeCount) {
            instr = getNextInstr(instr);
            assert(instr);
            testEqual(instrName(instr->code()), instrName(next2));
        }
    }
}
/// This method test the undo functionality of the text
void ReplaceSelectionCommandTest::testUndo()
{
    TextEditorWidget* widget = new TextEditorWidget();
    TextEditorController* ctrl = widget->controller();
    TextDocument *doc = widget->textDocument();
    TextBuffer* buf = doc->buffer();

    // check if we can set the txt  
    ctrl->replaceSelection("test");
    testEqual( buf->text(), "test" );

    // test basic, undo/redo
        ctrl->undo();
        testEqual( buf->text(), "" );

        // test coalesce
        ctrl->replaceSelection("emma");
        ctrl->replaceSelection(" sarah",true);
        ctrl->replaceSelection(" david",true);
        testEqual( buf->text(), "emma sarah david" );
        ctrl->undo();
        testEqual( buf->text(), "emma" );

        ctrl->redo();
        testEqual( buf->text(), "emma sarah david");

    // test ranged replacement
        doc->textUndoStack()->clear();
        buf->setText("Blommers");

        testEqual( buf->text(), "Blommers" );

        // now replace 'mm' by nothing
        TextRangeSet sel( doc );
        sel.addRange(3,5);
        ctrl->replaceRangeSet( sel, "" );
        testEqual( buf->text(), "Bloers" );

        ctrl->undo();
        testEqual( buf->text(), "Blommers" );
        ctrl->redo();
        testEqual( buf->text(), "Bloers" );



        delete widget;
}
/// basic test for line iteration
void RangeSetLineIteratorTest::testBasicIteration()
{
    CharTextDocument doc;
    doc.setText( QStringLiteral("a1|b2|c3|d4|e5|f6").replace("|","\n"));
    TextRangeSet ranges(&doc);
    ranges.addRange(0,0);   // line: 0
    ranges.addRange(1,1);   // line: 0
    ranges.addRange(2,7);   // line: 0-2
    ranges.addRange(12,15); // line: 4-5

    RangeSetLineIterator itr(&ranges);

    testTrue( itr.hasNext() );
    testEqual( itr.next(), 0 );
    testTrue( itr.hasNext() );
    testEqual( itr.next(), 1 );
    testTrue( itr.hasNext() );
    testEqual( itr.next(), 2 );
    testTrue( itr.hasNext() );
    testEqual( itr.next(), 4 );
    testTrue( itr.hasNext() );
    testEqual( itr.next(), 5 );
    testFalse( itr.hasNext() );
    testEqual( itr.next(), -1 );
}
Example #9
0
void testInterp(const string& input, const string& expected)
{
    Stack<Value> result;
    Stack<Env*> globals;
    bool ok = CompileModule(input, globals, result);
    testTrue(ok);
    Stack<Block*> block(result.as<CodeObject>()->block());
    ok = interp->exec(block, result);
    if (!ok)
        cerr << "Error: " << result.asObject()->as<Exception>()->message() << endl;
    testTrue(ok);
    testEqual(repr(result.get()), expected);
}
void TextDocumentScopesTest::testRindexOf()
{
    TextScopeManager* sm = Edbee::instance()->scopeManager();
    TextScope* source = sm->refTextScope("aa.bb.cc.dd.ee");

    testEqual( source->rindexOf( sm->refTextScope("aa.bb") ), 0 );
    testEqual( source->rindexOf( sm->refTextScope("cc.dd") ), 2 );
    testEqual( source->rindexOf( sm->refTextScope("dd.ee") ), 3 );
    testEqual( source->rindexOf( sm->refTextScope("bb.aa") ), -1 );

    testEqual( source->rindexOf( sm->refTextScope("*.cc.*.ee") ), 1 );
    testEqual( source->rindexOf( sm->refTextScope("aa.bb.cc.dd.ee") ), 0 );

    testEqual( source->rindexOf( sm->refTextScope("*") ), 4 );
}
Example #11
0
xrCompressor::ALIAS* xrCompressor::testALIAS(IReader* base, u32 crc, u32& a_tests)
{
	xr_multimap<u32,ALIAS>::iterator I = aliases.lower_bound(base->length());

	while (I!=aliases.end() && (I->first==base->length()))
	{
		if (I->second.crc == crc)
		{
			a_tests	++;
			if (testEqual(I->second.path,base))	
			{
				return	&I->second;
			}
		}
		I++;
	}
	return NULL;
}
Example #12
0
static int testString(const CString& in, const CString& url,
		const CString& html, const CString& sql) {
	CString out;
	int errors = 0;

	// Encode, then decode again and check we still got the same string

	out = in.Escape_n(CString::EASCII, CString::EURL);
	errors += testEqual(out, url, "EURL encode");
	out = out.Escape_n(CString::EURL, CString::EASCII);
	errors += testEqual(out, in, "EURL decode");

	out = in.Escape_n(CString::EASCII, CString::EHTML);
	errors += testEqual(out, html, "EHTML encode");
	out = out.Escape_n(CString::EHTML, CString::EASCII);
	errors += testEqual(out, in, "EHTML decode");

	out = in.Escape_n(CString::EASCII, CString::ESQL);
	errors += testEqual(out, sql, "ESQL encode");
	out = out.Escape_n(CString::ESQL, CString::EASCII);
	errors += testEqual(out, in, "ESQL decode");

	return errors;
}
Example #13
0
int AgiEngine::testIfCode(int lognum) {
    int ec = true;
    int retval = true;
    uint8 op = 0;
    uint8 notTest = false;
    uint8 orTest = false;
    uint16 lastIp = ip;
    uint8 p[16] = { 0 };
    bool end_test = false;

    while (retval && !(shouldQuit() || _restartGame) && !end_test) {
        if (_debug.enabled && (_debug.logic0 || lognum))
            debugConsole(lognum, lTEST_MODE, NULL);

        lastIp = ip;
        op = *(code + ip++);
        memmove(p, (code + ip), 16);

        switch (op) {
        case 0xFF:	// END IF, TEST true
            end_test = true;
            break;
        case 0xFD:
            notTest = !notTest;
            continue;
        case 0xFC:	// OR
            // if or_test is ON and we hit 0xFC, end of OR, then
            // or is STILL false so break.
            if (orTest) {
                ec = false;
                retval = false;
                end_test = true;
            }

            orTest = true;
            continue;

        case 0x00:
            // return true?
            end_test = true;
            break;
        case 0x01:
            ec = testEqual(p[0], p[1]);
            if (p[0] == 11)
                _timerHack++;
            break;
        case 0x02:
            ec = testEqual(p[0], getvar(p[1]));
            if (p[0] == 11 || p[1] == 11)
                _timerHack++;
            break;
        case 0x03:
            ec = testLess(p[0], p[1]);
            if (p[0] == 11)
                _timerHack++;
            break;
        case 0x04:
            ec = testLess(p[0], getvar(p[1]));
            if (p[0] == 11 || p[1] == 11)
                _timerHack++;
            break;
        case 0x05:
            ec = testGreater(p[0], p[1]);
            if (p[0] == 11)
                _timerHack++;
            break;
        case 0x06:
            ec = testGreater(p[0], getvar(p[1]));
            if (p[0] == 11 || p[1] == 11)
                _timerHack++;
            break;
        case 0x07:
            ec = testIsSet(p[0]);
            break;
        case 0x08:
            ec = testIsSet(getvar(p[0]));
            break;
        case 0x09:
            ec = testHas(p[0]);
            break;
        case 0x0A:
            ec = testObjInRoom(p[0], p[1]);
            break;
        case 0x0B:
            ec = testPosn(p[0], p[1], p[2], p[3], p[4]);
            break;
        case 0x0C:
            ec = testController(p[0]);
            break;
        case 0x0D:
            ec = testKeypressed();
            break;
        case 0x0E:
            ec = testSaid(p[0], (uint8 *) code + (ip + 1));
            ip = lastIp;
            ip++;	// skip opcode
            ip += p[0] * 2;	// skip num_words * 2
            ip++;	// skip num_words opcode
            break;
        case 0x0F:
            debugC(7, kDebugLevelScripts, "comparing [%s], [%s]", _game.strings[p[0]], _game.strings[p[1]]);
            ec = testCompareStrings(p[0], p[1]);
            break;
        case 0x10:
            ec = testObjInBox(p[0], p[1], p[2], p[3], p[4]);
            break;
        case 0x11:
            ec = testObjCenter(p[0], p[1], p[2], p[3], p[4]);
            break;
        case 0x12:
            ec = testObjRight(p[0], p[1], p[2], p[3], p[4]);
            break;
        case 0x13: // Unknown test command 19
            // My current theory is that this command checks whether the ego is currently moving
            // and that that movement has been caused using the mouse and not using the keyboard.
            // I base this theory on the game's behavior on an Amiga emulator, not on disassembly.
            // This command is used at least in the Amiga version of Gold Rush! v2.05 1989-03-09
            // (AGI 2.316) in logics 1, 3, 5, 6, 137 and 192 (Logic.192 revealed this command's nature).
            // TODO: Check this command's implementation using disassembly just to be sure.
            ec = _game.viewTable[0].flags & ADJ_EGO_XY;
            debugC(7, kDebugLevelScripts, "op_test: in.motion.using.mouse = %s (Amiga-specific testcase 19)", ec ? "true" : "false");
            break;
        default:
            ec = false;
            end_test = true;
        }

        if (!end_test) {
            if (op <= 0x12)
                ip += logicNamesTest[op].numArgs;

            // exchange ec value
            if (notTest)
                ec = !ec;

            // not is only enabled for 1 test command
            notTest = false;

            if (orTest && ec) {
                // a true inside an OR statement passes
                // ENTIRE statement scan for end of OR

                // CM: test for opcode < 0xfc changed from 'op' to
                //     '*(code+ip)', to avoid problem with the 0xfd (NOT)
                //     opcode byte. Changed a bad ip += ... ip++ construct.
                //     This should fix the crash with Larry's logic.0 code:
                //
                //     if ((isset(4) ||
                //          !isset(2) ||
                //          v30 == 2 ||
                //          v30 == 1)) {
                //       goto Label1;
                //     }
                //
                //     The bytecode is:
                //     ff fc 07 04 fd 07 02 01 1e 02 01 1e 01 fc ff

                // find end of OR
                while (*(code + ip) != 0xFC) {
                    if (*(code + ip) == 0x0E) {	// said
                        ip++;

                        // cover count + ^words
                        ip += 1 + ((*(code + ip)) * 2);
                        continue;
                    }

                    if (*(code + ip) < 0xFC)
                        ip += logicNamesTest[*(code + ip)].numArgs;
                    ip++;
                }
                ip++;

                orTest = false;
                retval = true;
            } else {
                retval = orTest ? retval || ec : retval && ec;
            }
        }
    }

    // if false, scan for end of IP?
    if (retval)
        ip += 2;
    else {
        ip = lastIp;
        while (*(code + ip) != 0xff) {
            if (*(code + ip) == 0x0e) {
                ip++;
                ip += (*(code + ip)) * 2 + 1;
            } else if (*(code + ip) < 0xfc) {
                ip += logicNamesTest[*(code + ip)].numArgs;
                ip++;
            } else {
                ip++;
            }
        }
        ip++;		// skip over 0xFF
        ip += READ_LE_UINT16(code + ip) + 2;
    }

    if (_debug.enabled && (_debug.logic0 || lognum))
        debugConsole(lognum, 0xFF, retval ? "=true" : "=false");

    return retval;
}
Example #14
0
void TextUndoStackTest::testMultiCaretUndoIssue196()
{
    TextEditorWidget widget;
    TextDocument* doc = widget.textDocument();
    TextEditorController* controller = widget.controller();
//    TextUndoStack* undoStack = doc->textUndoStack();

    controller->replace(0,0,"1a2b3c4d",0);                  // 1a|2b|3c4d
    controller->moveCaretToOffset(2,false);
    controller->addCaretAtOffset(4);

    testEqual( doc->text(), "1a2b3c4d" );
    testEqual( controller->textSelection()->rangesAsString(), "2>2,4>4");

    RemoveCommand del( RemoveCommand::RemoveChar, RemoveCommand::Right );

    del.execute(controller);
    testEqual( doc->text(), "1abc4d" );                          // 1a|b|c4d
    testEqual( controller->textSelection()->rangesAsString(), "2>2,3>3");

    del.execute(controller);
    testEqual( controller->textSelection()->rangesAsString(), "2>2");
    testEqual( doc->text(), "1a4d" );                       // 1a||4d



    del.execute(controller);
    testEqual( doc->text(), "1ad" );
    testEqual( controller->textSelection()->rangesAsString(), "2>2");

    del.execute(controller);
    testEqual( doc->text(), "1a" );
    testEqual( controller->textSelection()->rangesAsString(), "2>2");

    del.execute(controller);
    testEqual( doc->text(), "1a" );
    testEqual( controller->textSelection()->rangesAsString(), "2>2");

//qlog_info() << "STACK: ---------------------------------------";
//qlog_info() << doc->textUndoStack()->dumpStack();
//qlog_info() << "----------------------------------------------";

    controller->undo();

    testEqual( doc->text(), "1a2b3c4d" );
    testEqual( controller->textSelection()->rangesAsString(), "2>2,4>4");


/*


==== after 1 delete ===

  1a|2b|3c4d =>  1a|b|c4d


 UndoStack
 =====================
 "-|Complex::TextChangeGroup(3/3)
 - 0: SelectionTextChange
 - 1: SingleTextChange:2:0:2
 - 2: SingleTextChange:3:0:3

==== after 2 deletes ===

  1a|b|c4d =>  1a|4d


UndoStack
=====================
"-|Complex::TextChangeGroup(3/3)
 - 0: SelectionTextChange
 - 1: SingleTextChange:2:0:2b         (2b en 3c is verwijderd... Dit is nog goed!)
 - 2: SingleTextChange:2:0:3c

 ==== after 3 deletes ===

  1a|4d =>  1a|d

  // NEW STACK ITEM REQUIRED!!!!

 UndoStack
 =====================
 "-|Complex::TextChangeGroup(3/3)
 - 0: SelectionTextChange
 - 1: SingleTextChange:2:0:2b4
 - 2: SingleTextChange:1:0:3c          <= hier zou de 4 achter moeten staan!!! (Dit is nooit te bepalen, omdat je niet weet welke carets verdwenen zijn)

*/


}
Example #15
0
void
testInvocationCount(int expected)
{
    testEqual(nInvocation, expected);
}
Example #16
0
void
testFailureCount(int expected)
{
    testEqual(nFailure, expected);
}
Example #17
0
void
testRetryCount(int expected)
{
    testEqual(nRetry, expected);
}
Example #18
0
/// A special split-merge
/// Which means the second change was placed OVER the previous one on both side
/// (A) 1:1:
/// (B) 0:0:axb
/// (M) 0:2:ab
///
/// - mergeResult("1:1:", "0:2:axb"), "0:2:ab");
///  (text = a[x]b[y]e)
///
///
void TextChangeTest::testMerge7_splitMergeInvert()
{
    {
        TextChange a(1,1,"") ;
        TextChange* b = new TextChange(0,0,"axb");
        testTrue( a.giveAndMerge(0,b));
        testEqual( a.offset(),0 );
        testEqual( a.docLength(),0 );
        testEqual( a.storedText(), "ab" );
    }

    {
        TextChange a(0,1,"") ;
        TextChange* b = new TextChange(0,0,"xab");
        testTrue( a.giveAndMerge(0,b));
        testEqual( a.offset(),0 );
        testEqual( a.docLength(),0 );
        testEqual( a.storedText(), "ab" );
    }


    {
        TextChange a(0,2,"") ;                                       // |abcd => [xy]abcd             (0:2:)
        TextChange* b = new TextChange(1,0,"yab");             // x[yab]cd  => xcd              (1:0:yab)
        testTrue( a.giveAndMerge(0,b));                                    // =>                            (0:1:ab)
        testEqual( a.offset(),0 );
        testEqual( a.docLength(),1 );
        testEqual( a.storedText(), "ab" );
    }

    {
        TextChange a(1,3,"bc") ;                                     // a[bc]def     => aXYZdef        (1:3:bc)
        TextChange* b = new TextChange(4,1,"de");              // aXYZ[de]f    => aXYZ?f         (4:1:de)
        testTrue( a.giveAndMerge(0,b));                                    // =>                             (1:4:bcde)
        testEqual( a.offset(),1 );
        testEqual( a.docLength(),4 );
        testEqual( a.storedText(), "bcde" );
    }

    {
        TextChange a(1,4,"bc") ;                                     // a[bc]def     => aKLMNdef       (1:4:bc)
        TextChange* b = new TextChange(2,2,"L");               // aK[L]MNdef  => aKxyMNdef       (2:2:L)
        testTrue( a.giveAndMerge(0,b));                                    // =>                             (1:5:bc)
        testEqual( a.offset(),1 );
        testEqual( a.docLength(),5 );
        testEqual( a.storedText(), "bc" );
    }

}