public void Should_Output_Equivalent_JavaScript_Module_Member_For_Sylvre_Module_Member( string module, string member, string expected) { string output = SylvreJavaScriptMappings.GetEquivalentJavaScriptMemberOfModule( module, member); Assert.AreEqual(expected, output); }
/// <summary> /// Handles the variable_complex_reference if it is a Sylvre library reference. /// </summary> /// <param name="context">The variable_complex_reference to handle.</param> /// <param name="isFunctionCall">Whether the Sylvre library reference is a function call or not.</param> private void HandleSylvreLibraryReference(Variable_complex_referenceContext context, bool isFunctionCall) { var suffixes = context.variable_suffix(); if (suffixes == null || suffixes.Length == 0) { _transpileErrors.Add(new SylvreTranspileError { CharPositionInLine = context.variable_reference().Stop.Column, Line = context.variable_reference().Stop.Line, Symbol = context.variable_reference().Stop.Text, Message = _sylvreMissingModuleMessage }); return; } var firstSuffixContext = context.variable_suffix()[0]; if (firstSuffixContext.index_reference() != null) { _transpileErrors.Add(new SylvreTranspileError { CharPositionInLine = firstSuffixContext.index_reference().Start.Column + 1, // Column number 1 behind, zero based index? Line = firstSuffixContext.index_reference().Start.Line, Symbol = firstSuffixContext.index_reference().Start.Text, Message = _sylvreLibraryIndexReferenceInvalidMessage }); return; } var moduleContext = firstSuffixContext.member_reference().variable_reference(); string module = moduleContext.GetText(); if (!SylvreJavaScriptMappings.DoesSylvreModuleExist(module)) { _transpileErrors.Add(new SylvreTranspileError { CharPositionInLine = moduleContext.Start.Column + 1, // Column number 1 behind, zero based index? Line = moduleContext.Start.Line, Symbol = moduleContext.Start.Text, Message = _sylvreInvalidModuleMessage }); return; } string jsEquivalentModule = SylvreJavaScriptMappings.GetEquivalentJavaScriptModule(module); if (!string.IsNullOrWhiteSpace(jsEquivalentModule)) { _output.Append(jsEquivalentModule) .Append('.'); } if (suffixes.Length <= 1) { _transpileErrors.Add(new SylvreTranspileError { CharPositionInLine = moduleContext.Stop.Column, Line = moduleContext.Stop.Line, Symbol = moduleContext.Stop.Text, Message = _sylvreMissingModuleMemberMessage }); return; } var secondSuffixContext = context.variable_suffix()[1]; if (secondSuffixContext.index_reference() != null) { _transpileErrors.Add(new SylvreTranspileError { CharPositionInLine = secondSuffixContext.index_reference().Start.Column + 1, // Column number 1 behind, zero based index? Line = secondSuffixContext.index_reference().Start.Line, Symbol = secondSuffixContext.index_reference().Start.Text, Message = _sylvreModuleIndexReferenceInvalidMessage }); return; } var moduleMemberContext = secondSuffixContext.member_reference().variable_reference(); string moduleMember = moduleMemberContext.GetText(); if (!SylvreJavaScriptMappings.DoesSylvreMemberOfModuleExist(module, moduleMember)) { _transpileErrors.Add(new SylvreTranspileError { CharPositionInLine = moduleMemberContext.Start.Column + 1, // Column number 1 behind, zero based index? Line = moduleMemberContext.Start.Line, Symbol = moduleMemberContext.Start.Text, Message = _sylvreInvalidModuleMemberMessage }); return; } _output.Append(SylvreJavaScriptMappings.GetEquivalentJavaScriptMemberOfModule( module, moduleMember)); for (int i = 2; i < context.variable_suffix().Length; i++) { VisitVariable_suffix(context.variable_suffix()[i]); } }