<commit_before>package groovy.inspect;

import junit.framework.TestCase;

import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.*;

public class InspectorTest extends TestCase implements Serializable {
    public String someField = "only for testing";
    public static final String SOME_CONST = "only for testing";

    public InspectorTest(String name) {
        super(name);
    }

    public void testCtor() {
        new Inspector(new Object());
        try {
            new Inspector(null);
            fail("should have thown IllegalArgumentException");
        } catch (Exception expected) {
        }
    }

    public void testClassProps() {
        Inspector insp = new Inspector(this);
        String[] classProps = insp.getClassProps();
        assertEquals("package groovy.inspect",classProps[Inspector.CLASS_PACKAGE_IDX]);
        assertEquals("public class InspectorTest",classProps[Inspector.CLASS_CLASS_IDX]);
        assertEquals("implements Serializable ",classProps[Inspector.CLASS_INTERFACE_IDX]);
        assertEquals("extends TestCase",classProps[Inspector.CLASS_SUPERCLASS_IDX]);
        assertEquals("is Primitive: false, is Array: false, is Groovy: false",classProps[Inspector.CLASS_OTHER_IDX]);
    }
    public void testMethods() {
        Inspector insp = new Inspector(new Object());
        Object[] methods = insp.getMethods();
        assertEquals(10, methods.length);
        String[] names = {"hashCode","getClass","wait","wait","wait","equals","notify","notifyAll","toString","java.lang.Object"};
        assertNameEquals(names, methods);
        String[] details = {"JAVA","public final","Object","void","wait","long, int","InterruptedException"};
        assertContains(methods, details);
        // ctors are not considered static !
        String[] ctorDetails = {"JAVA","public","Object","Object","java.lang.Object","",""};
        assertContains(methods, ctorDetails);
    }

    public void testStaticMethods() {
        Inspector insp = new Inspector(this);
        Object[] methods = insp.getMethods();
        for (int i = 0; i < methods.length; i++) {
            String[] strings = (String[]) methods[i];
            if(strings[1].indexOf("static") > -1) return; // ok, found one static method
        }
        fail("there should have been at least one static method in this TestCase, e.g. 'fail'.");
    }
    public void testMetaMethods() {
        Inspector insp = new Inspector(new Object());
        Object[] metaMethods = insp.getMetaMethods();
        assertEquals(33, metaMethods.length);
        String[] names = { "sleep", "sleep", "println", "println", "println", "find", "print", "print", "each", "invokeMethod", "asType",
                           "inspect", "is", "isCase", "identity", "getAt", "putAt", "dump", "getMetaPropertyValues",  "getProperties",
                           "use", "use", "use", "printf", "printf", "eachWithIndex", "every", "any", "grep", "collect", "collect", "findAll", "findIndexOf"
                         };
        assertNameEquals(names, metaMethods);
        String[] details = {"GROOVY","public","Object","void","println","Object","n/a"};
        assertContains(metaMethods, details);
    }

    public void testStaticMetaMethods() {
        Matcher matcher = Pattern.compile("").matcher("");
        Inspector insp = new Inspector(matcher);
        Object[] metaMethods = insp.getMetaMethods();
        assertUnique(Inspector.sort(Arrays.asList(metaMethods)));
        String[] details = {"GROOVY","public static","Matcher","Matcher","getLastMatcher","","n/a"};
        assertContains(metaMethods, details);
    }

    public void testFields() {
        Inspector insp = new Inspector(this);
        Object[] fields = insp.getPublicFields();
        assertEquals(2, fields.length);
        String[] names = { "someField","SOME_CONST" };
        assertNameEquals(names, fields);
        String[] details = {"JAVA","public","InspectorTest","String","someField","\"only for testing\""};
        assertContains(fields, details);
    }
    public void testProperties() {
        Inspector insp = new Inspector(this);
        Object[] fields = insp.getPropertyInfo();
        assertEquals(4, fields.length);
        String[] names = { "SOME_CONST","someField","class","name"};
        assertNameEquals(names, fields);
        String[] details = {"GROOVY","public","n/a","String","name","\"testProperties\""};
        assertContains(fields, details);
    }

    private void assertNameEquals(String[] names, Object[] metaMethods) {
        Set metaSet = new HashSet();
        for (int i = 0; i < metaMethods.length; i++) {
            String[] strings = (String[]) metaMethods[i];
            metaSet.add(strings[Inspector.MEMBER_NAME_IDX]);
        }
        Set nameSet = new HashSet(Arrays.asList(names));
        assertEquals(nameSet, metaSet);
    }<commit_msg>as normal fields are no longer shown as properties this test was adapted to the now correct logic<commit_after>package groovy.inspect;

import junit.framework.TestCase;

import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.*;

public class InspectorTest extends TestCase implements Serializable {
    public String someField = "only for testing";
    public static final String SOME_CONST = "only for testing";

    public InspectorTest(String name) {
        super(name);
    }

    public void testCtor() {
        new Inspector(new Object());
        try {
            new Inspector(null);
            fail("should have thown IllegalArgumentException");
        } catch (Exception expected) {
        }
    }

    public void testClassProps() {
        Inspector insp = new Inspector(this);
        String[] classProps = insp.getClassProps();
        assertEquals("package groovy.inspect",classProps[Inspector.CLASS_PACKAGE_IDX]);
        assertEquals("public class InspectorTest",classProps[Inspector.CLASS_CLASS_IDX]);
        assertEquals("implements Serializable ",classProps[Inspector.CLASS_INTERFACE_IDX]);
        assertEquals("extends TestCase",classProps[Inspector.CLASS_SUPERCLASS_IDX]);
        assertEquals("is Primitive: false, is Array: false, is Groovy: false",classProps[Inspector.CLASS_OTHER_IDX]);
    }
    public void testMethods() {
        Inspector insp = new Inspector(new Object());
        Object[] methods = insp.getMethods();
        assertEquals(10, methods.length);
        String[] names = {"hashCode","getClass","wait","wait","wait","equals","notify","notifyAll","toString","java.lang.Object"};
        assertNameEquals(names, methods);
        String[] details = {"JAVA","public final","Object","void","wait","long, int","InterruptedException"};
        assertContains(methods, details);
        // ctors are not considered static !
        String[] ctorDetails = {"JAVA","public","Object","Object","java.lang.Object","",""};
        assertContains(methods, ctorDetails);
    }

    public void testStaticMethods() {
        Inspector insp = new Inspector(this);
        Object[] methods = insp.getMethods();
        for (int i = 0; i < methods.length; i++) {
            String[] strings = (String[]) methods[i];
            if(strings[1].indexOf("static") > -1) return; // ok, found one static method
        }
        fail("there should have been at least one static method in this TestCase, e.g. 'fail'.");
    }
    public void testMetaMethods() {
        Inspector insp = new Inspector(new Object());
        Object[] metaMethods = insp.getMetaMethods();
        assertEquals(33, metaMethods.length);
        String[] names = { "sleep", "sleep", "println", "println", "println", "find", "print", "print", "each", "invokeMethod", "asType",
                           "inspect", "is", "isCase", "identity", "getAt", "putAt", "dump", "getMetaPropertyValues",  "getProperties",
                           "use", "use", "use", "printf", "printf", "eachWithIndex", "every", "any", "grep", "collect", "collect", "findAll", "findIndexOf"
                         };
        assertNameEquals(names, metaMethods);
        String[] details = {"GROOVY","public","Object","void","println","Object","n/a"};
        assertContains(metaMethods, details);
    }

    public void testStaticMetaMethods() {
        Matcher matcher = Pattern.compile("").matcher("");
        Inspector insp = new Inspector(matcher);
        Object[] metaMethods = insp.getMetaMethods();
        assertUnique(Inspector.sort(Arrays.asList(metaMethods)));
        String[] details = {"GROOVY","public static","Matcher","Matcher","getLastMatcher","","n/a"};
        assertContains(metaMethods, details);
    }

    public void testFields() {
        Inspector insp = new Inspector(this);
        Object[] fields = insp.getPublicFields();
        assertEquals(2, fields.length);
        String[] names = { "someField","SOME_CONST" };
        assertNameEquals(names, fields);
        String[] details = {"JAVA","public","InspectorTest","String","someField","\"only for testing\""};
        assertContains(fields, details);
    }
    
    public void testProperties() {
        Inspector insp = new Inspector(this);
        Object[] properties = insp.getPropertyInfo();
        assertEquals(2, properties.length);
        String[] names = {"class","name" };
        assertNameEquals(names, properties);
        String[] details = {"GROOVY", "public", "n/a", "Class", "class", "class groovy.inspect.InspectorTest"};
        assertContains(properties, details);
    }

    private void assertNameEquals(String[] names, Object[] metaMethods) {
        Set metaSet = new HashSet();
        for (int i = 0; i < metaMethods.length; i++) {
            String[] strings = (String[]) metaMethods[i];
            metaSet.add(strings[Inspector.MEMBER_NAME_IDX]);
        }
        Set nameSet = new HashSet(Arrays.asList(names));
        assertEquals(nameSet, metaSet);
    }
{'fraction_non_alphanumeric': 0.1477307034316192, 'fraction_numerical': 0.002012679883264567, 'mean_word_length': 3.223544411389715, 'pattern_counts': {'":': 0, '<': 7, '<?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': '922101', 'n_tokens_mistral': 2689, 'n_tokens_neox': 2617, 'n_words': 641}