Class TestUtils


  • public class TestUtils
    extends java.lang.Object
    • Field Detail

      • MARKUP_SELECTION_START_CHAR

        public static final char MARKUP_SELECTION_START_CHAR
        See Also:
        Constant Field Values
      • MARKUP_SELECTION_END_CHAR

        public static final char MARKUP_SELECTION_END_CHAR
        See Also:
        Constant Field Values
      • MARKUP_CARET

        public static final java.lang.String MARKUP_CARET
      • MARKUP_SELECTION_START

        public static final java.lang.String MARKUP_SELECTION_START
      • MARKUP_SELECTION_END

        public static final java.lang.String MARKUP_SELECTION_END
      • CARET_PREDICATE

        @NotNull
        public static final @NotNull CharPredicate CARET_PREDICATE
      • MARKUP_PREDICATE

        @NotNull
        public static final @NotNull CharPredicate MARKUP_PREDICATE
      • EMPTY_OFFSETS

        public static final int[] EMPTY_OFFSETS
      • DISABLED_OPTION_PREFIX_CHAR

        public static final char DISABLED_OPTION_PREFIX_CHAR
        See Also:
        Constant Field Values
      • DISABLED_OPTION_PREFIX

        public static final java.lang.String DISABLED_OPTION_PREFIX
      • EMBED_TIMED_OPTION_NAME

        public static final java.lang.String EMBED_TIMED_OPTION_NAME
        See Also:
        Constant Field Values
      • FAIL_OPTION_NAME

        public static final java.lang.String FAIL_OPTION_NAME
        See Also:
        Constant Field Values
      • FILE_EOL_OPTION_NAME

        public static final java.lang.String FILE_EOL_OPTION_NAME
        See Also:
        Constant Field Values
      • IGNORE_OPTION_NAME

        public static final java.lang.String IGNORE_OPTION_NAME
        See Also:
        Constant Field Values
      • NO_FILE_EOL_OPTION_NAME

        public static final java.lang.String NO_FILE_EOL_OPTION_NAME
        See Also:
        Constant Field Values
      • TIMED_ITERATIONS_OPTION_NAME

        public static final java.lang.String TIMED_ITERATIONS_OPTION_NAME
        See Also:
        Constant Field Values
      • TIMED_OPTION_NAME

        public static final java.lang.String TIMED_OPTION_NAME
        See Also:
        Constant Field Values
      • EMBED_TIMED

        public static final DataKey<java.lang.Boolean> EMBED_TIMED
      • FAIL

        public static final DataKey<java.lang.Boolean> FAIL
      • IGNORE

        public static final DataKey<java.lang.Boolean> IGNORE
      • NO_FILE_EOL

        public static final DataKey<java.lang.Boolean> NO_FILE_EOL
      • TIMED

        public static final DataKey<java.lang.Boolean> TIMED
      • TIMED_ITERATIONS

        public static final DataKey<java.lang.Integer> TIMED_ITERATIONS
      • TIMED_FORMAT_STRING

        public static final java.lang.String TIMED_FORMAT_STRING
        See Also:
        Constant Field Values
      • INCLUDED_DOCUMENT

        public static final DataKey<java.lang.String> INCLUDED_DOCUMENT
      • SOURCE_PREFIX

        public static final DataKey<java.lang.String> SOURCE_PREFIX
      • SOURCE_SUFFIX

        public static final DataKey<java.lang.String> SOURCE_SUFFIX
      • SOURCE_INDENT

        public static final DataKey<java.lang.String> SOURCE_INDENT
      • NO_FILE_EOL_FALSE

        public static final DataHolder NO_FILE_EOL_FALSE
      • UNLOAD_EXTENSIONS

        public static final DataKey<java.util.Collection<java.lang.Class<? extends Extension>>> UNLOAD_EXTENSIONS
      • LOAD_EXTENSIONS

        public static final DataKey<java.util.Collection<Extension>> LOAD_EXTENSIONS
      • EMPTY_OPTIONS

        private static final DataHolder EMPTY_OPTIONS
      • CUSTOM_OPTION

        public static final DataKey<java.util.function.BiFunction<java.lang.String,​java.lang.String,​DataHolder>> CUSTOM_OPTION
      • BANNER_LENGTH

        public static final int BANNER_LENGTH
    • Constructor Detail

      • TestUtils

        public TestUtils()
    • Method Detail

      • processOption

        public static DataHolder processOption​(@NotNull
                                               @NotNull java.util.Map<java.lang.String,​? extends DataHolder> optionsMap,
                                               @NotNull
                                               @NotNull java.lang.String option)
      • buildOptionsMap

        @NotNull
        public static <T> @NotNull java.util.HashMap<java.lang.String,​T> buildOptionsMap​(@NotNull
                                                                                               @NotNull java.lang.String[] options,
                                                                                               @NotNull
                                                                                               @NotNull java.util.function.BiFunction<ExampleOption,​java.lang.Integer,​T> factory)
      • buildOptionsMap

        @NotNull
        public static <T> @NotNull java.util.HashMap<java.lang.String,​T> buildOptionsMap​(boolean ensureAllBuiltInPresent,
                                                                                               @NotNull
                                                                                               @NotNull java.lang.Object[][] options,
                                                                                               @NotNull
                                                                                               @NotNull java.util.function.BiFunction<ExampleOption,​java.lang.Object[],​T> factory)
        Build options map, optionally ensuring all built-ins are present
        Type Parameters:
        T - type of value in the map
        Parameters:
        ensureAllBuiltInPresent - if true, throws IllegalStateException if some built-in options are missing
        options - array of object arrays, each row represents option values with first element ([0]) of each row being an option string. Each row is passed to factory to allow creating custom options.
        factory - factory creating a type from ExampleOption and given row of parameters
        Returns:
        constructed hash map of option name
      • addSpecSection

        @NotNull
        public static @NotNull Pair<java.lang.String,​java.lang.Integer> addSpecSection​(@NotNull
                                                                                             @NotNull java.lang.String headingLine,
                                                                                             @NotNull
                                                                                             @NotNull java.lang.String headingText,
                                                                                             java.lang.String[] sectionHeadings)
      • getOptions

        public static DataHolder getOptions​(@NotNull
                                            @NotNull SpecExample example,
                                            @Nullable
                                            @Nullable java.lang.String optionSets,
                                            @NotNull
                                            @NotNull java.util.function.Function<java.lang.String,​DataHolder> optionsProvider)
        process comma separated list of option sets and combine them for final set to use
        Parameters:
        example - spec example instance for which options are being processed
        optionSets - comma separate list of option set names
        optionsProvider - function to take a string option name and provide settings based on it
        Returns:
        combined set from applying these options together
      • throwIllegalStateException

        public static void throwIllegalStateException​(@NotNull
                                                      @NotNull SpecExample example,
                                                      @NotNull
                                                      @NotNull java.lang.String option)
      • throwIgnoredOption

        public static void throwIgnoredOption​(@NotNull
                                              @NotNull SpecExample example,
                                              @NotNull
                                              @NotNull java.lang.String optionSets,
                                              @NotNull
                                              @NotNull java.lang.String option)
      • ast

        @NotNull
        public static @NotNull java.lang.String ast​(@NotNull
                                                    @NotNull Node node)
      • addSpecExample

        public static java.lang.String addSpecExample​(boolean includeExampleStart,
                                                      java.lang.String source,
                                                      java.lang.String html,
                                                      java.lang.String ast,
                                                      java.lang.String optionsSet)
      • addSpecExample

        public static void addSpecExample​(boolean includeExampleStart,
                                          java.lang.StringBuilder sb,
                                          java.lang.String source,
                                          java.lang.String html,
                                          java.lang.String ast,
                                          java.lang.String optionsSet,
                                          boolean includeExampleCoords,
                                          java.lang.String section,
                                          int number)
      • addSpecExample

        public static void addSpecExample​(boolean includeExampleStart,
                                          boolean toVisibleSpecText,
                                          java.lang.StringBuilder sb,
                                          java.lang.String source,
                                          java.lang.String html,
                                          java.lang.String ast,
                                          java.lang.String optionsSet,
                                          boolean includeExampleCoords,
                                          java.lang.String section,
                                          int number)
      • addSpecExample

        public static void addSpecExample​(boolean useTestExample,
                                          boolean includeExampleStart,
                                          boolean toVisibleSpecText,
                                          java.lang.StringBuilder sb,
                                          java.lang.String source,
                                          java.lang.String html,
                                          java.lang.String ast,
                                          java.lang.String optionsSet,
                                          boolean includeExampleCoords,
                                          java.lang.String section,
                                          int number)
      • addSpecExample

        public static void addSpecExample​(java.lang.CharSequence exampleBreak,
                                          java.lang.CharSequence sectionBreak,
                                          boolean includeExampleStart,
                                          boolean toVisibleSpecText,
                                          java.lang.Appendable out,
                                          java.lang.CharSequence source,
                                          java.lang.CharSequence html,
                                          java.lang.CharSequence ast,
                                          java.lang.CharSequence optionsSet,
                                          boolean includeExampleCoords,
                                          java.lang.CharSequence section,
                                          int number)
      • addSpecExample

        public static void addSpecExample​(java.lang.CharSequence exampleBreakOpen,
                                          java.lang.CharSequence htmlBreak,
                                          java.lang.CharSequence astBreak,
                                          java.lang.CharSequence exampleBreakClose,
                                          boolean includeExampleStart,
                                          boolean toVisibleSpecText,
                                          java.lang.Appendable out,
                                          java.lang.CharSequence source,
                                          java.lang.CharSequence html,
                                          java.lang.CharSequence ast,
                                          java.lang.CharSequence optionsSet,
                                          boolean includeExampleCoords,
                                          java.lang.CharSequence section,
                                          java.lang.CharSequence number,
                                          java.lang.CharSequence exampleKeyword,
                                          java.lang.CharSequence optionsKeyword)
      • showTabs

        @Deprecated
        public static java.lang.String showTabs​(java.lang.String s)
        Deprecated.
        Parameters:
        s - text to convert to visible chars
        Returns:
        spec test special chars converted to visible
      • toVisibleSpecText

        public static java.lang.String toVisibleSpecText​(java.lang.String s)
        Parameters:
        s - text to convert to visible chars
        Returns:
        spec test special chars converted to visible
      • toVisibleSpecText

        public static java.lang.CharSequence toVisibleSpecText​(java.lang.CharSequence s)
        Parameters:
        s - text to convert to visible chars
        Returns:
        spec test special chars converted to visible
      • unShowTabs

        @Deprecated
        public static java.lang.String unShowTabs​(java.lang.String s)
        Parameters:
        s - text to convert to from visible chars to normal
        Returns:
        spec test special visible chars converted to normal
      • fromVisibleSpecText

        public static java.lang.String fromVisibleSpecText​(java.lang.String s)
        Parameters:
        s - text to convert to from visible chars to normal
        Returns:
        spec test special visible chars converted to normal
      • fromVisibleSpecText

        public static java.lang.CharSequence fromVisibleSpecText​(java.lang.CharSequence s)
        Parameters:
        s - text to convert to from visible chars to normal
        Returns:
        spec test special visible chars converted to normal
      • trimTrailingEOL

        public static java.lang.String trimTrailingEOL​(java.lang.String parseSource)
      • getFormattedTimingInfo

        public static java.lang.String getFormattedTimingInfo​(int iterations,
                                                              long start,
                                                              long parse,
                                                              long render)
      • getFormattedTimingInfo

        public static java.lang.String getFormattedTimingInfo​(java.lang.String section,
                                                              int exampleNumber,
                                                              int iterations,
                                                              long start,
                                                              long parse,
                                                              long render)
      • getFormattedSection

        @NotNull
        public static @NotNull java.lang.String getFormattedSection​(java.lang.String section,
                                                                    int exampleNumber)
      • getResolvedSpecResourcePath

        @NotNull
        public static @NotNull java.lang.String getResolvedSpecResourcePath​(@NotNull
                                                                            @NotNull java.lang.String testClassName,
                                                                            @NotNull
                                                                            @NotNull java.lang.String resourcePath)
      • getAbsoluteSpecResourcePath

        @NotNull
        public static @NotNull java.lang.String getAbsoluteSpecResourcePath​(@NotNull
                                                                            @NotNull java.lang.String testClassPath,
                                                                            @NotNull
                                                                            @NotNull java.lang.String resourceRootPath,
                                                                            @NotNull
                                                                            @NotNull java.lang.String resourcePath)
      • getSpecResourceFileUrl

        @NotNull
        public static @NotNull java.lang.String getSpecResourceFileUrl​(@NotNull
                                                                       @NotNull java.lang.Class<?> resourceClass,
                                                                       @NotNull
                                                                       @NotNull java.lang.String resourcePath)
      • getTestData

        public static java.util.ArrayList<java.lang.Object[]> getTestData​(@NotNull
                                                                          @NotNull ResourceLocation location)
      • getUrlWithLineNumber

        @NotNull
        public static @NotNull java.lang.String getUrlWithLineNumber​(@NotNull
                                                                     @NotNull java.lang.String fileUrl,
                                                                     int lineNumber)
      • adjustedFileUrl

        public static java.lang.String adjustedFileUrl​(@NotNull
                                                       @NotNull java.net.URL url)
      • combineDefaultOptions

        @Nullable
        public static @Nullable DataHolder combineDefaultOptions​(@Nullable
                                                                 @Nullable DataHolder[] defaultOptions)
      • optionsMaps

        @Nullable
        public static @Nullable java.util.Map<java.lang.String,​? extends DataHolder> optionsMaps​(@Nullable
                                                                                                       @Nullable java.util.Map<java.lang.String,​? extends DataHolder> other,
                                                                                                       @Nullable
                                                                                                       @Nullable java.util.Map<java.lang.String,​? extends DataHolder> overrides)
      • dataHolders

        @Nullable
        public static @Nullable DataHolder[] dataHolders​(@Nullable
                                                         @Nullable DataHolder other,
                                                         @Nullable
                                                         @Nullable DataHolder[] overrides)
      • getTestResourceRootDirectoryForModule

        @NotNull
        public static @NotNull java.lang.String getTestResourceRootDirectoryForModule​(@NotNull
                                                                                      @NotNull java.lang.Class<?> resourceClass,
                                                                                      @NotNull
                                                                                      @NotNull java.lang.String moduleRootPackage)
      • getRootDirectoryForModule

        @NotNull
        public static @NotNull java.lang.String getRootDirectoryForModule​(@NotNull
                                                                          @NotNull java.lang.Class<?> resourceClass,
                                                                          @NotNull
                                                                          @NotNull java.lang.String moduleDirectoryName)
      • customStringOption

        public static DataHolder customStringOption​(@NotNull
                                                    @NotNull java.lang.String option,
                                                    @Nullable
                                                    @Nullable java.lang.String params,
                                                    @NotNull
                                                    @NotNull java.util.function.Function<java.lang.String,​DataHolder> resolver)
      • customIntOption

        public static DataHolder customIntOption​(@NotNull
                                                 @NotNull java.lang.String option,
                                                 @Nullable
                                                 @Nullable java.lang.String params,
                                                 @NotNull
                                                 @NotNull java.util.function.Function<java.lang.Integer,​DataHolder> resolver)
      • bannerText

        @NotNull
        public static @NotNull java.lang.String bannerText​(@NotNull
                                                           @NotNull java.lang.String message)
      • appendBanner

        public static void appendBanner​(@NotNull
                                        @NotNull java.lang.StringBuilder out,
                                        @NotNull
                                        @NotNull java.lang.String banner)
      • appendBanner

        public static void appendBanner​(@NotNull
                                        @NotNull java.lang.StringBuilder out,
                                        @NotNull
                                        @NotNull java.lang.String banner,
                                        boolean addBlankLine)
      • appendBannerIfNeeded

        public static void appendBannerIfNeeded​(@NotNull
                                                @NotNull java.lang.StringBuilder out,
                                                @NotNull
                                                @NotNull java.lang.String banner)