/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-â
âvi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8                                :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2021 Justine Alexandra Roberts Tunney                              â
â                                                                              â
â Permission to use, copy, modify, and/or distribute this software for         â
â any purpose with or without fee is hereby granted, provided that the         â
â above copyright notice and this permission notice appear in all copies.      â
â                                                                              â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL                â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED                â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE             â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL         â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR        â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER               â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR             â
â PERFORMANCE OF THIS SOFTWARE.                                                â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/mem/mem.h"
#include "libc/mem/gc.internal.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"

TEST(utf16to32, testChinese) {
  EXPECT_STREQ(
      L"å¤©å°çé» å®å®æ´ªè æ¥æçæ è¾°å®¿åå¼  å¯æ¥æå¾ ç§æ¶å¬è"
      L"é°é¦æå² å¾åè°é³ äºè¾è´é¨ é²ç»ä¸ºé éçä¸½æ°´ çåºæå"
      L"åå·å·¨é ç ç§°å¤å æçææ° èéè¥å§ æµ·å¸æ²³æ·¡ é³æ½ç¾½ç¿"
      L"é¾å¸ç«å¸ é¸å®äººç å§å¶æå­ ä¹æè¡£è£³ æ¨ä½è®©å½ æèé¶å",
      gc(utf16to32(u"å¤©å°çé» å®å®æ´ªè æ¥æçæ è¾°å®¿åå¼  å¯æ¥æå¾ ç§æ¶å¬è"
                   u"é°é¦æå² å¾åè°é³ äºè¾è´é¨ é²ç»ä¸ºé éçä¸½æ°´ çåºæå"
                   u"åå·å·¨é ç ç§°å¤å æçææ° èéè¥å§ æµ·å¸æ²³æ·¡ é³æ½ç¾½ç¿"
                   u"é¾å¸ç«å¸ é¸å®äººç å§å¶æå­ ä¹æè¡£è£³ æ¨ä½è®©å½ æèé¶å",
                   -1, 0)));
}

TEST(utf16to32, testAstralPlanesGothic) {
  EXPECT_STREQ(L"ð°ð±ð²ð³ð´ðµð¶ð·ð¸ð¹ðºð»ð¼ð½ð¾ð¿ððððððððððð"
               L"ð°ð±ð²ð³ð´ðµð¶ð·ð¸ð¹ðºð»ð¼ð½ð¾ð¿ððððððððððð"
               L"ð°ð±ð²ð³ð´ðµð¶ð·ð¸ð¹ðºð»ð¼ð½ð¾ð¿ððððððððððð"
               L"ð°ð±ð²ð³ð´ðµð¶ð·ð¸ð¹ðºð»ð¼ð½ð¾ð¿ððððððððððð",
               gc(utf16to32(u"ð°ð±ð²ð³ð´ðµð¶ð·ð¸ð¹ðºð»ð¼ð½ð¾ð¿ððððððððððð"
                            u"ð°ð±ð²ð³ð´ðµð¶ð·ð¸ð¹ðºð»ð¼ð½ð¾ð¿ððððððððððð"
                            u"ð°ð±ð²ð³ð´ðµð¶ð·ð¸ð¹ðºð»ð¼ð½ð¾ð¿ððððððððððð"
                            u"ð°ð±ð²ð³ð´ðµð¶ð·ð¸ð¹ðºð»ð¼ð½ð¾ð¿ððððððððððð",
                            -1, 0)));
}

BENCH(utf16to8, bench) {
  size_t n;
  char16_t *h;
  h = gc(utf8to16(kHyperion, kHyperionSize, &n));
  EZBENCH2("utf16to32", donothing, free(utf16to32(h, n, 0)));
}
