<commit_before>/**
 * jemul8 - JavaScript x86 Emulator
 * http://jemul8.com/
 *
 * Copyright 2013 jemul8.com (http://github.com/asmblah/jemul8)
 * Released under the MIT license
 * http://jemul8.com/MIT-LICENSE.txt
 */

/*global define, Uint8Array */
define([
    "js/util",
    "tools/Factory/Assembler",
    "js/Decoder"
], function (
    util,
    AssemblerFactory,
    Decoder
) {
    "use strict";

    describe("Decoder", function () {
        var assembler,
            decoder;

        beforeEach(function () {
            assembler = new AssemblerFactory().create();

            decoder = new Decoder();
            decoder.init();
        });

        describe("decode()", function () {
            util.each([
                {
                    is32BitCodeSegment: false,
                    assembly: "hlt",
                    expectedName: "HLT",
                    expectedOperands: []
                },
                {
                    is32BitCodeSegment: false,
                    assembly: "nop",
                    expectedName: "NOP",
                    expectedOperands: []
                },
                // Tests that 16-bit register is used
                {
                    is32BitCodeSegment: false,
                    assembly: "mov ax, 1",
                    expectedName: "MOV",
                    expectedOperands: [
                        {
                            baseRegister: "AX",
                            indexRegister: null,
                            scale: 1,
                            segmentRegister: "DS"
                        },
                        {
                            immediate: 1,
                            immediateSize: 2,
                            scale: 1,
                            segmentRegister: "DS"
                        }
                    ]
                },
                // Tests that operand-size prefix is respected
                {
                    is32BitCodeSegment: false,
                    is32BitOperandSize: true, // Via prefix
                    assembly: "mov eax, 1",
                    expectedName: "MOV",
                    expectedOperands: [
                        {
                            baseRegister: "EAX",
                            indexRegister: null,
                            scale: 1,
                            segmentRegister: "DS"
                        },
                        {
                            immediate: 1,
                            immediateSize: 4,
                            scale: 1,
                            segmentRegister: "DS"
                        }
                    ]
                },
                // Tests addressing method "A"
                {
                    is32BitCodeSegment: false,
                    is32BitOperandSize: true,
                    assembly: "call 0x3456:0xABCD",
                    expectedName: "CALLF",
                    expectedOperands: [
                        {
                            immediate: 0x3456ABCD,
                            immediateSize: 4,
                            scale: 1,
                            segmentRegister: "DS"
                        }
                    ]
                },
                // Tests addressing method "C"
                {<commit_msg>Instruction in test has a 16-bit operand size, not 32-bit<commit_after>/**
 * jemul8 - JavaScript x86 Emulator
 * http://jemul8.com/
 *
 * Copyright 2013 jemul8.com (http://github.com/asmblah/jemul8)
 * Released under the MIT license
 * http://jemul8.com/MIT-LICENSE.txt
 */

/*global define, Uint8Array */
define([
    "js/util",
    "tools/Factory/Assembler",
    "js/Decoder"
], function (
    util,
    AssemblerFactory,
    Decoder
) {
    "use strict";

    describe("Decoder", function () {
        var assembler,
            decoder;

        beforeEach(function () {
            assembler = new AssemblerFactory().create();

            decoder = new Decoder();
            decoder.init();
        });

        describe("decode()", function () {
            util.each([
                {
                    is32BitCodeSegment: false,
                    assembly: "hlt",
                    expectedName: "HLT",
                    expectedOperands: []
                },
                {
                    is32BitCodeSegment: false,
                    assembly: "nop",
                    expectedName: "NOP",
                    expectedOperands: []
                },
                // Tests that 16-bit register is used
                {
                    is32BitCodeSegment: false,
                    assembly: "mov ax, 1",
                    expectedName: "MOV",
                    expectedOperands: [
                        {
                            baseRegister: "AX",
                            indexRegister: null,
                            scale: 1,
                            segmentRegister: "DS"
                        },
                        {
                            immediate: 1,
                            immediateSize: 2,
                            scale: 1,
                            segmentRegister: "DS"
                        }
                    ]
                },
                // Tests that operand-size prefix is respected
                {
                    is32BitCodeSegment: false,
                    is32BitOperandSize: true, // Via prefix
                    assembly: "mov eax, 1",
                    expectedName: "MOV",
                    expectedOperands: [
                        {
                            baseRegister: "EAX",
                            indexRegister: null,
                            scale: 1,
                            segmentRegister: "DS"
                        },
                        {
                            immediate: 1,
                            immediateSize: 4,
                            scale: 1,
                            segmentRegister: "DS"
                        }
                    ]
                },
                // Tests addressing method "A"
                {
                    is32BitCodeSegment: false,
                    is32BitOperandSize: false,
                    assembly: "call 0x3456:0xABCD",
                    expectedName: "CALLF",
                    expectedOperands: [
                        {
                            immediate: 0x3456ABCD,
                            immediateSize: 4,
                            scale: 1,
                            segmentRegister: "DS"
                        }
                    ]
                },
                // Tests addressing method "C"
                {
{'fraction_non_alphanumeric': 0.08146609289212049, 'fraction_numerical': 0.015729336696839295, 'mean_word_length': 0.7479253112033195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6417105', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1440, 'n_words': 311}