glyph_ut.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * glyph_ut.cpp --
  3. *
  4. * Copyright (c) 2007-2010, Dmitry Prokoptsev <dprokoptsev@gmail.com>,
  5. * Alexander Gololobov <agololobov@gmail.com>
  6. *
  7. * This file is part of Pire, the Perl Incompatible
  8. * Regular Expressions library.
  9. *
  10. * Pire is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Lesser Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * Pire is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Lesser Public License for more details.
  19. * You should have received a copy of the GNU Lesser Public License
  20. * along with Pire. If not, see <http://www.gnu.org/licenses>.
  21. */
  22. #include <pire.h>
  23. #include <extra/glyphs.h>
  24. #include "stub/cppunit.h"
  25. #include "common.h"
  26. Y_UNIT_TEST_SUITE(Glyphs) {
  27. Pire::Fsm ParseFsm(const char* regexp)
  28. {
  29. TVector<wchar32> ucs4;
  30. Pire::Encodings::Utf8().FromLocal(regexp, regexp + strlen(regexp), std::back_inserter(ucs4));
  31. return Pire::Lexer(ucs4).SetEncoding(Pire::Encodings::Utf8()).AddFeature(Pire::Features::GlueSimilarGlyphs()).Parse().Surround();
  32. }
  33. #define NOGL_REGEXP(str) REGEXP2(str, "u")
  34. #define GL_REGEXP(str) SCANNER(ParseFsm(str))
  35. Y_UNIT_TEST(Glyphs)
  36. {
  37. NOGL_REGEXP("regexp") {
  38. ACCEPTS("regexp");
  39. DENIES("r\xD0\xB5g\xD0\xB5\xD1\x85\xD1\x80");
  40. }
  41. GL_REGEXP("regexp") {
  42. ACCEPTS("regexp");
  43. ACCEPTS("r\xD0\xB5g\xD0\xB5\xD1\x85\xD1\x80");
  44. }
  45. NOGL_REGEXP("r\xD0\xB5g\xD0\xB5\xD1\x85\xD1\x80") {
  46. DENIES("regexp");
  47. ACCEPTS("r\xD0\xB5g\xD0\xB5\xD1\x85\xD1\x80");
  48. }
  49. GL_REGEXP("r\xD0\xB5g\xD0\xB5\xD1\x85\xD1\x80") {
  50. ACCEPTS("regexp");
  51. ACCEPTS("r\xD0\xB5g\xD0\xB5\xD1\x85\xD1\x80");
  52. }
  53. }
  54. }