summary refs log tree commit diff stats
path: root/tests/newconfig
Commit message (Expand)AuthorAgeFilesLines
* [feature] Added os.delEnv; add delEnv support to nimscript too (#11466)Kaushal Modi2019-06-151-0/+5
* cleanup tests; don't use non-working 'msg' spec fieldAraq2018-11-231-1/+1
* Fixes #9671 (#9750)Randy Smith2018-11-191-3/+0
* travis: run 'koch testinstall' on OSXAndreas Rumpf2018-09-181-8/+14
* Add a few useful os calls to nimscript (#7442)genotrance2018-04-101-0/+47
* Fixes 7283 (#7284)cooldome2018-03-051-1/+8
* fixes #6327Andreas Rumpf2017-09-051-0/+2
* fixes #5228Andreas Rumpf2017-03-182-1/+3
* make tests green againAndreas Rumpf2016-07-101-1/+1
* Nimscript: added support for 'patchFile'Andreas Rumpf2016-07-093-2/+10
* Nimscript supports hint() and warning() procs; refs #3688Andreas Rumpf2016-07-081-0/+3
* cleaned up ospaths moduleAraq2015-10-121-0/+3
* NimScript: --define works as expectedAraq2015-09-302-0/+4
* implements experimental new config system based on NimScriptAraq2015-08-162-0/+21
ht: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
discard """
  nimout: '''"muhaha"
proc poo(x, y: int) =
  let y = x
  echo ["poo"]'''
"""

import macros

const
  foo = "muhaha"

proc poo(x, y: int) =
  let y = x
  echo "poo"

macro m(x: typed): untyped =
  echo repr x.getImpl

m(foo)
m(poo)

#------------

macro checkOwner(x: typed, check_id: static[int]): untyped =
  let sym = case check_id:
    of 0: x
    of 1: x.getImpl.body[0][0][0]
    of 2: x.getImpl.body[0][0][^1]
    of 3: x.getImpl.body[1][0]
    else: x
  result = newStrLitNode($sym.owner.symKind)

macro isSameOwner(x, y: typed): untyped =
  result =
    if x.owner == y.owner: bindSym"true"
    else: bindSym"false"


static:
  doAssert checkOwner(foo, 0) == "nskModule"
  doAssert checkOwner(poo, 0) == "nskModule"
  doAssert checkOwner(poo, 1) == "nskProc"
  doAssert checkOwner(poo, 2) == "nskProc"
  doAssert checkOwner(poo, 3) == "nskModule"
  doAssert isSameOwner(foo, poo)
  doAssert isSameOwner(foo, echo) == false
  doAssert isSameOwner(poo, len) == false

#---------------------------------------------------------------

macro check_gen_proc(ex: typed): (bool, bool) =
  let lenChoice = bindsym"len"
  var is_equal = false 
  var is_instance_of = false 
  for child in lenChoice:
    if not is_equal:
      is_equal = ex[0] == child
    if not is_instance_of:
      is_instance_of = isInstantiationOf(ex[0], child)
         
  result = nnkTupleConstr.newTree(newLit(is_equal), newLit(is_instance_of))

# check that len(seq[int]) is not equal to bindSym"len", but is instance of it
let a = @[1,2,3]
assert: check_gen_proc(len(a)) == (false, true)