コード例 #1
0
        public IEnumerable <IOperationProvider> ConfigureFromJObject(JObject rawConfiguration, IDirectory templateRoot)
        {
            string original    = rawConfiguration.ToString("original");
            string replacement = rawConfiguration.ToString("replacement");
            string id          = rawConfiguration.ToString("id");
            bool   onByDefault = rawConfiguration.ToBool("onByDefault");

            JArray      onlyIf     = rawConfiguration.Get <JArray>("onlyIf");
            TokenConfig coreConfig = original.TokenConfigBuilder();

            if (onlyIf != null)
            {
                foreach (JToken entry in onlyIf.Children())
                {
                    if (!(entry is JObject x))
                    {
                        continue;
                    }

                    string      before      = entry.ToString("before");
                    string      after       = entry.ToString("after");
                    TokenConfig entryConfig = coreConfig;

                    if (!string.IsNullOrEmpty(before))
                    {
                        entryConfig = entryConfig.OnlyIfBefore(before);
                    }

                    if (!string.IsNullOrEmpty(after))
                    {
                        entryConfig = entryConfig.OnlyIfAfter(after);
                    }

                    yield return(new Replacement(entryConfig, replacement, id, onByDefault));
                }
            }
            else
            {
                yield return(new Replacement(coreConfig, replacement, id, onByDefault));
            }
        }
コード例 #2
0
        public void VerifyTokenTrieLookArounds(string original, int checkPosition, int expectedPosition, bool success, string after, string value, string before)
        {
            byte[] data = Encoding.UTF8.GetBytes(original);

            TokenTrie   t       = new TokenTrie();
            TokenConfig builder = (value ?? "").TokenConfigBuilder();

            if (!string.IsNullOrEmpty(after))
            {
                builder = builder.OnlyIfAfter(after);
            }

            if (!string.IsNullOrEmpty(before))
            {
                builder = builder.OnlyIfBefore(before);
            }

            t.AddToken(builder.ToToken(Encoding.UTF8));

            int pos = checkPosition;

            Assert.Equal(success, t.GetOperation(data, data.Length, ref pos, out int token));
            Assert.Equal(expectedPosition, pos);
        }