<commit_before>////////////////////////////////////////////////////////////////////////////////
// Name:      test-lexers.cpp
// Purpose:   Implementation for wxExtension unit testing
// Author:    <NAME>
// Copyright: (c) 2016 <NAME>
////////////////////////////////////////////////////////////////////////////////

#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/extension/lexers.h>
#include <wx/extension/managedframe.h>
#include <wx/extension/stc.h>
#include "test.h"

TEST_CASE("wxExLexers", "[stc][lexer]")
{
  wxExSTC* stc = new wxExSTC(GetFrame(), "hello stc");
  AddPane(GetFrame(), stc);
  
  REQUIRE( wxExLexers::Get() != nullptr);
  REQUIRE(!wxExLexers::Get()->GetLexers().empty());
  
  // Test lexer and global macros.
  for (const auto& macro : std::vector<
    std::pair<
      std::pair<std::string,std::string>,
      std::string>> {
    {{"number","asm"},"2"},
    {{"number","cpp"},"4"},
    {{"XXX","global"},"XXX"},
    {{"mark_lcorner","global"},"10"},
    {{"mark_circle","global"},"0"},
    {{"iv_none","global"},"0"}})
  {
    REQUIRE( wxExLexers::Get()->ApplyMacro(
      macro.first.first, macro.first.second) == macro.second);
  }

  // At this moment we have no global properties.
  REQUIRE( wxExLexers::Get()->GetProperties().empty());
  
  wxExLexers::Get()->Apply(stc);

  REQUIRE(!wxExLexers::Get()->GetLexers().empty());

  REQUIRE( wxExLexers::Get()->FindByFileName(
    GetTestFile()).GetScintillaLexer() == "cpp");
    
  REQUIRE( wxExLexers::Get()->FindByName(
    "xxx").GetScintillaLexer().empty());
    
  REQUIRE( wxExLexers::Get()->FindByName(
    "cpp").GetScintillaLexer() == "cpp");
    
  for (const auto& findby : std::vector<std::pair<
    std::string, 
    std::pair<std::string, std::string>>> {
    {"// this is a cpp comment text",{"cpp","cpp"}},
    {"#!/bin/sh",{"bash","sh"}},
    {"#!/bin/csh",{"bash","csh"}},
    {"#!/bin/tcsh",{"bash","tcsh"}},
    {"#!/bin/bash",{"bash","bash"}},
    {"#!/bin/bash\n",{"bash","bash"}},
    {"#!/usr/bin/csh",{"bash","bash"}},
    {"<html>",{"hypertext","hypertext"}},
    {"<?xml",{"hypertext","xml"}}})
  {
    REQUIRE( wxExLexers::Get()->FindByText(
      findby.first).GetScintillaLexer() == findby.second.first);
    REQUIRE( wxExLexers::Get()->FindByText(
      findby.first).GetDisplayLexer() == findby.second.second);
  }
    
  REQUIRE( wxExLexers::Get()->GetFileName().IsOk());

  REQUIRE(!wxExLexers::Get()->GetMacros("global").empty());
  REQUIRE(!wxExLexers::Get()->GetMacros("cpp").empty());
  REQUIRE(!wxExLexers::Get()->GetMacros("pascal").empty());
  REQUIRE( wxExLexers::Get()->GetMacros("XXX").empty());
  
  REQUIRE(!wxExLexers::Get()->GetTheme().empty());
  REQUIRE( wxExLexers::Get()->GetThemeOk());
  REQUIRE(!wxExLexers::Get()->GetThemeMacros().empty());
  REQUIRE( wxExLexers::Get()->GetThemes() > 1);

  wxExLexers::Get()->SetThemeNone();
  REQUIRE( wxExLexers::Get()->GetTheme().empty());
  REQUIRE(!wxExLexers::Get()->GetThemeOk());
  wxExLexers::Get()->RestoreTheme();
  REQUIRE( wxExLexers::Get()->GetTheme() == "torte");
  REQUIRE( wxExLexers::Get()->GetThemeOk());
  
  REQUIRE(!wxExLexers::Get()->IndicatorIsLoaded(wxExIndicator(99, -1)));
  REQUIRE( wxExLexers::Get()->IndicatorIsLoaded(wxExIndicator(0, -1)));
  REQUIRE( wxExLexers::Get()->MarkerIsLoaded(wxExMarker(0, -1)));
  
  wxString lexer("cpp");
  wxExLexers::Get()->ShowDialog(GetFrame(), lexer, wxEmptyString, false);
  wxExLexers::Get()->ShowThemeDialog(GetFrame(), wxEmptyString, false);
  
  REQUIRE(!wxExLexers::Get()->GetKeywords("cpp").empty());
  REQUIRE(!wxExLexers::Get()->GetKeywords("csh").empty());
  REQUIRE( wxExLexers::Get()->GetKeywords("xxx").empty());
  REQUIRE( wxExLexers::Get()->GetKeywords(wxEmptyString).empty());<commit_msg>fixed test<commit_after>////////////////////////////////////////////////////////////////////////////////
// Name:      test-lexers.cpp
// Purpose:   Implementation for wxExtension unit testing
// Author:    <NAME>
// Copyright: (c) 2016 <NAME>
////////////////////////////////////////////////////////////////////////////////

#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/extension/lexers.h>
#include <wx/extension/managedframe.h>
#include <wx/extension/stc.h>
#include "test.h"

TEST_CASE("wxExLexers", "[stc][lexer]")
{
  wxExSTC* stc = new wxExSTC(GetFrame(), "hello stc");
  AddPane(GetFrame(), stc);
  
  REQUIRE( wxExLexers::Get() != nullptr);
  REQUIRE(!wxExLexers::Get()->GetLexers().empty());
  
  // Test lexer and global macros.
  for (const auto& macro : std::vector<
    std::pair<
      std::pair<std::string,std::string>,
      std::string>> {
    {{"number","asm"},"2"},
    {{"number","cpp"},"4"},
    {{"XXX","global"},"XXX"},
    {{"mark_lcorner","global"},"10"},
    {{"mark_circle","global"},"0"},
    {{"iv_none","global"},"0"}})
  {
    REQUIRE( wxExLexers::Get()->ApplyMacro(
      macro.first.first, macro.first.second) == macro.second);
  }

  // At this moment we have no global properties.
  REQUIRE( wxExLexers::Get()->GetProperties().empty());
  
  wxExLexers::Get()->Apply(stc);

  REQUIRE(!wxExLexers::Get()->GetLexers().empty());

  REQUIRE( wxExLexers::Get()->FindByFileName(
    GetTestFile()).GetScintillaLexer() == "cpp");
    
  REQUIRE( wxExLexers::Get()->FindByName(
    "xxx").GetScintillaLexer().empty());
    
  REQUIRE( wxExLexers::Get()->FindByName(
    "cpp").GetScintillaLexer() == "cpp");
    
  for (const auto& findby : std::vector<std::pair<
    std::string, 
    std::pair<std::string, std::string>>> {
    {"// this is a cpp comment text",{"cpp","cpp"}},
    {"#!/bin/sh",{"bash","sh"}},
    {"#!/bin/csh",{"bash","csh"}},
    {"#!/bin/tcsh",{"bash","tcsh"}},
    {"#!/bin/bash",{"bash","bash"}},
    {"#!/bin/bash\n",{"bash","bash"}},
    {"#!/usr/bin/csh",{"bash","bash"}},
    {"<html>",{"hypertext","hypertext"}},
    {"<?xml",{"hypertext","xml"}}})
  {
    REQUIRE( wxExLexers::Get()->FindByText(
      findby.first).GetScintillaLexer() == findby.second.first);
    REQUIRE( wxExLexers::Get()->FindByText(
      findby.first).GetDisplayLexer() == findby.second.second);
  }
    
  REQUIRE( wxExLexers::Get()->GetFileName().IsOk());

  REQUIRE(!wxExLexers::Get()->GetMacros("global").empty());
  REQUIRE(!wxExLexers::Get()->GetMacros("cpp").empty());
  REQUIRE(!wxExLexers::Get()->GetMacros("pascal").empty());
  REQUIRE( wxExLexers::Get()->GetMacros("XXX").empty());
  
  REQUIRE(!wxExLexers::Get()->GetTheme().empty());
  REQUIRE( wxExLexers::Get()->GetThemeOk());
  REQUIRE(!wxExLexers::Get()->GetThemeMacros().empty());
  REQUIRE( wxExLexers::Get()->GetThemes() > 1);

  wxExLexers::Get()->SetThemeNone();
  REQUIRE( wxExLexers::Get()->GetTheme().empty());
  REQUIRE(!wxExLexers::Get()->GetThemeOk());
  wxExLexers::Get()->RestoreTheme();
  REQUIRE( wxExLexers::Get()->GetTheme() == "studio");
  REQUIRE( wxExLexers::Get()->GetThemeOk());
  
  REQUIRE(!wxExLexers::Get()->IndicatorIsLoaded(wxExIndicator(99, -1)));
  REQUIRE( wxExLexers::Get()->IndicatorIsLoaded(wxExIndicator(0, -1)));
  REQUIRE( wxExLexers::Get()->MarkerIsLoaded(wxExMarker(0, -1)));
  
  wxString lexer("cpp");
  wxExLexers::Get()->ShowDialog(GetFrame(), lexer, wxEmptyString, false);
  wxExLexers::Get()->ShowThemeDialog(GetFrame(), wxEmptyString, false);
  
  REQUIRE(!wxExLexers::Get()->GetKeywords("cpp").empty());
  REQUIRE(!wxExLexers::Get()->GetKeywords("csh").empty());
  REQUIRE( wxExLexers::Get()->GetKeywords("xxx").empty());
  REQUIRE( wxExLexers::Get()->GetKeywords(wxEmptyString).empty());
{'fraction_non_alphanumeric': 0.280106100795756, 'fraction_numerical': 0.004774535809018567, 'mean_word_length': 4.09527027027027, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '7639936', 'n_tokens_mistral': 2894, 'n_tokens_neox': 2679, 'n_words': 336}