<commit_before>assert = require 'assert'
util = require 'fy/test_util'

{_tokenize} = require '../src/tokenizer'
{_parse   } = require '../src/grammar'
{_type_inference, type_inference} = require '../src/type_inference'
full = (t)->
  tok = _tokenize(t)
  ast = _parse(tok, mode_full:true)
  _type_inference ast[0], {}
  ast[0]

describe 'type_inference section', ()->
  describe 'const', ()->
    kv =
      "1"     : "int"
      "0777"  : "int"
      "0x1"   : "int"
      "0b1"   : "int"
      "1.0"   : "float"
      "'1'"   : "string"
      '"1"'   : "string"
      "true"  : "bool"
      "false" : "bool"
      "a"     : undefined
      "@"     : undefined
      "'1'\n1": "int" # test stmt_plus
    for k,v of kv
      do (k,v)->
        it JSON.stringify(k), ()->
          ast = full k
          assert.equal ast.mx_hash.type?.toString(), v
  
  # describe 'special const', ()-><commit_msg>Type inference: add tests for regexp const<commit_after>assert = require 'assert'
util = require 'fy/test_util'

{_tokenize} = require '../src/tokenizer'
{_parse   } = require '../src/grammar'
{_type_inference, type_inference} = require '../src/type_inference'
full = (t)->
  tok = _tokenize(t)
  ast = _parse(tok, mode_full:true)
  _type_inference ast[0], {}
  ast[0]

describe 'type_inference section', ()->
  describe 'const', ()->
    kv =
      "1"           : "int"
      "0777"        : "int"
      "0x1"         : "int"
      "0b1"         : "int"
      "1.0"         : "float"
      "'1'"         : "string"
      '"1"'         : "string"
      '/ab+c/i'     : "regexp"
      '///ab+c///i' : "regexp"
      "true"        : "bool"
      "false"       : "bool"
      "a"           : undefined
      "@"           : undefined
      "'1'\n1"      : "int" # test stmt_plus
    for k,v of kv
      do (k,v)->
        it JSON.stringify(k), ()->
          ast = full k
          assert.equal ast.mx_hash.type?.toString(), v
  
  # describe 'special const', ()->
{'fraction_non_alphanumeric': 0.18408975012748596, 'fraction_numerical': 0.017338092809790925, 'mean_word_length': 1.881057268722467, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2237157', 'n_tokens_mistral': 729, 'n_tokens_neox': 719, 'n_words': 158}