<commit_before>/*******************************************************************************
 * Copyright (c) 2015-2016 Oak Ridge National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.csstudio.display.builder.model.macros;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

import org.junit.Test;

/** JUnit test of macro handling
 *  @author <NAME>
 */
@SuppressWarnings("nls")
public class MacrosUnitTest
{
    /** Test check for unresolved macros
     *  @throws Exception on error
     */
    @Test
    public void testCheck() throws Exception
    {
        assertThat(MacroHandler.containsMacros("Plain Text"), equalTo(false));
        assertThat(MacroHandler.containsMacros("${S}"), equalTo(true));
        assertThat(MacroHandler.containsMacros("This is $(S)"), equalTo(true));
        assertThat(MacroHandler.containsMacros("$(MACRO)"), equalTo(true));
        assertThat(MacroHandler.containsMacros("$(${MACRO})"), equalTo(true));
        assertThat(MacroHandler.containsMacros("Escaped \\$(S)"), equalTo(true));
        assertThat(MacroHandler.containsMacros("Escaped \\$(S) Used $(S)"), equalTo(true));
    }

    /** Test basic macro=value
     *  @throws Exception on error
     */
    @Test
    public void testMacros() throws Exception
    {
        final Macros macros = new Macros();
        macros.add("S", "BL7");
        macros.add("NAME", "Flint, Eugene");
        macros.add("TAB", "    ");
        macros.add("MACRO", "S");
        macros.add("traces[0].y_pv", "TheValueWaveform");
<commit_msg>Macros: Add name test<commit_after>/*******************************************************************************
 * Copyright (c) 2015-2016 Oak Ridge National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.csstudio.display.builder.model.macros;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

import org.junit.Test;

/** JUnit test of macro handling
 *  @author <NAME>
 */
@SuppressWarnings("nls")
public class MacrosUnitTest
{
    /** Test check of macro name
     */
    @Test
    public void testNames() throws Exception
    {
        assertThat(Macros.checkMacroName("ExampleMacro"), nullValue());
        assertThat(Macros.checkMacroName("My_Macro"), nullValue());
        assertThat(Macros.checkMacroName("My-Macro"), nullValue());
        assertThat(Macros.checkMacroName("Macro2"), nullValue());

        assertThat(Macros.checkMacroName("2MustStartWithCharacter"), not(nullValue()));
        assertThat(Macros.checkMacroName("-CannotHaveNon-CharacterAtStart"), not(nullValue()));
        assertThat(Macros.checkMacroName("No Spaces"), not(nullValue()));
    }

    /** Test check for unresolved macros
     *  @throws Exception on error
     */
    @Test
    public void testCheck() throws Exception
    {
        assertThat(MacroHandler.containsMacros("Plain Text"), equalTo(false));
        assertThat(MacroHandler.containsMacros("${S}"), equalTo(true));
        assertThat(MacroHandler.containsMacros("This is $(S)"), equalTo(true));
        assertThat(MacroHandler.containsMacros("$(MACRO)"), equalTo(true));
        assertThat(MacroHandler.containsMacros("$(${MACRO})"), equalTo(true));
        assertThat(MacroHandler.containsMacros("Escaped \\$(S)"), equalTo(true));
        assertThat(MacroHandler.containsMacros("Escaped \\$(S) Used $(S)"), equalTo(true));
    }

    /** Test basic macro=value
     *  @throws Exception on error
     */
    @Test
    public void testMacros() throws Exception
    {
        final Macros macros = new Macros();
        macros.add("S", "BL7");
        macros.add("NAME", "<NAME>");
        macros.add("TAB", "    ");
        macros.add("MACRO", "S");
        macros.add("traces[0].y_pv", "TheValueWaveform");

{'fraction_non_alphanumeric': 0.19433368310598112, 'fraction_numerical': 0.0062959076600209865, 'mean_word_length': 4.169197396963123, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4945989', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1333, 'n_words': 298}